Commit ca54d833 authored by Carsten  Rose's avatar Carsten Rose
Browse files

B6560 / Copy to clipboard: a) missing 'AS _yank', b) single and double ticks...

B6560 / Copy to clipboard: a) missing 'AS _yank', b) single and double ticks are not handled correctly
parent 2c90f05d
Pipeline #758 passed with stage
in 1 minute and 44 seconds
......@@ -1297,6 +1297,8 @@ const COLUMN_PAGEI = 'pagei';
const COLUMN_PAGEN = 'pagen';
const COLUMN_PAGES = 'pages';
const COLUMN_YANK = 'yank';
const COLUMN_PDF = 'pdf';
const COLUMN_FILE = 'file';
const COLUMN_ZIP = 'zip';
......
......@@ -145,4 +145,19 @@ class OnString {
return $urlParamNew;
}
/**
* Replace character ' and " by the unicode representation. This is useful for JS code, embedded in HTML code.
* <button onclick="new QfqNS.Clipboard({text: 'single tick -\u0027-' });">
*
* @param $str
* @return mixed
*/
public static function replaceByUnicode($str) {
$str = str_replace('"', '\u0022', $str);
$str = str_replace("'", '\u0027', $str);
return ($str);
}
}
......@@ -498,14 +498,14 @@ class Link {
* Iterate over all given token. Check for double definition.
*
* @param string $str
* @param array $tokenGiven
* @param array $rcTokenGiven - return an array with found token.
*
* @return array
* @throws CodeException
* @throws UserFormException
* @throws UserReportException
*/
private function fillParameter($str, array &$tokenGiven) {
private function fillParameter($str, array &$rcTokenGiven) {
// Define all possible vars: no more isset().
$vars = $this->initVars();
......@@ -530,14 +530,14 @@ class Link {
$value = isset($arr[1]) ? $arr[1] : '';
// Bookkeeping defined parameter.
if (isset($tokenGiven[$key])) {
if (isset($rcTokenGiven[$key])) {
throw new UserReportException ("Multiple definitions for key '$key'", ERROR_MULTIPLE_DEFINITION);
}
$tokenGiven[$key] = true;
$rcTokenGiven[$key] = true;
if (!isset($this->tableVarName[$key])) {
$msg[ERROR_MESSAGE_TO_USER]="Unknown link qualifier: '$key' - did you forget the one character qualifier?";
$msg[ERROR_MESSAGE_SUPPORT]=$str;
$msg[ERROR_MESSAGE_TO_USER] = "Unknown link qualifier: '$key' - did you forget the one character qualifier?";
$msg[ERROR_MESSAGE_SUPPORT] = $str;
throw new UserReportException (json_encode($msg), ERROR_UNKNOWN_LINK_QUALIFIER);
}
......@@ -551,12 +551,12 @@ class Link {
$value = $this->checkValue($key, $value);
// Store value
if ((isset($tokenGiven[TOKEN_DOWNLOAD]) || isset($tokenGiven[TOKEN_COPY_TO_CLIPBOARD])) &&
if ((isset($rcTokenGiven[TOKEN_DOWNLOAD]) || isset($rcTokenGiven[TOKEN_COPY_TO_CLIPBOARD])) &&
($key == TOKEN_PAGE || $key == TOKEN_URL || $key == TOKEN_URL_PARAM || $key == TOKEN_FILE || $key == TOKEN_FILE_DEPRECATED)) {
$vars[NAME_COLLECT_ELEMENTS][] = $key . ':' . $value;
unset($tokenGiven[$key]); // Skip Bookkeeping for TOKEN_URL_PARAM | TOKEN_FILE | TOKEN_URL.
unset($rcTokenGiven[$key]); // Skip Bookkeeping for TOKEN_URL_PARAM | TOKEN_FILE | TOKEN_URL.
continue;
} else {
// TOKEN_GLYPH should not treated as an regular image. Same applies to the other Glyph symbols, but those don't have a value, and therefore do not fill $vars['image'].
......@@ -587,17 +587,17 @@ class Link {
}
// Download Link needs some extra work
if ($tokenGiven[TOKEN_DOWNLOAD]) {
if ($rcTokenGiven[TOKEN_DOWNLOAD]) {
$vars = $this->buildDownloadLate($vars);
}
// CopyToClipboard (Download) Link needs some extra work
if ($tokenGiven[TOKEN_COPY_TO_CLIPBOARD]) {
if ($rcTokenGiven[TOKEN_COPY_TO_CLIPBOARD]) {
$vars = $this->buildCopyToClipboardLate($vars);
}
// Final Checks
$this->checkParam($tokenGiven, $vars);
$this->checkParam($rcTokenGiven, $vars);
return $vars;
}
......@@ -1433,7 +1433,7 @@ EOF;
// Clipboard Source
if ($vars[NAME_COPY_TO_CLIPBOARD] !== '') {
$jsAction = 'onClick';
$source = "{text: '" . $vars[NAME_COPY_TO_CLIPBOARD] . " '}";
$source = "{text: '" . OnString::replaceByUnicode($vars[NAME_COPY_TO_CLIPBOARD]) . "' }";
} elseif ($vars[NAME_FILE] !== '') {
$jsAction = 'onmousedown';
......
......@@ -738,6 +738,11 @@ class Report {
$content .= $this->link->renderLink($linkValue);
break;
case COLUMN_YANK:
$linkValue = $this->doYank($columnName, $columnValue);
$content .= $this->link->renderLink($linkValue);
break;
case COLUMN_PPDF:
case COLUMN_FFILE:
case COLUMN_ZZIP:
......@@ -1174,6 +1179,25 @@ class Report {
return ($columnValue);
}
/**
* Checks if a token 'y' is given. If not, prepend one.
*
* @param $columnName
* @param $columnValue
* @return string
* @throws UserFormException
*/
private function doYank($columnName, $columnValue) {
$token = KeyValueStringParser::parse($columnValue, PARAM_TOKEN_DELIMITER, PARAM_DELIMITER);
if (!isset($token[TOKEN_COPY_TO_CLIPBOARD])) {
$columnValue = TOKEN_COPY_TO_CLIPBOARD . PARAM_DELIMITER . $columnValue;
}
return $columnValue;
}
/**
* Renders _download: extract token and determine if any default value has to be applied
* [d:<exportFilename][U:<params>][u:<url>][f:file][t:<text>][a:<message>]|[o:<tooltip>]|[c:<class>]|[r:<render
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment