Skip to content

Commit

Permalink
allow to escape || character with \|| for tags
Browse files Browse the repository at this point in the history
  • Loading branch information
abaevbog committed Jun 13, 2023
1 parent 2cf66c3 commit 0bf6cdd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions controllers/TagsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ public function tags() {
// Filter for specific tags with "?tag=foo || bar"
$tagNames = !empty($this->queryParams['tag'])
? explode(' || ', $this->queryParams['tag']): array();
// Replace \|| with || to allow for tags with literal '||'.
$tagNames = array_map(function ($name) {
return str_replace("\||", "||", $name);
}, $tagNames);
Zotero_DB::beginTransaction();
foreach ($tagNames as $tagName) {
$tagIDs = Zotero_Tags::getIDs($this->objectLibraryID, $tagName);
Expand Down
5 changes: 5 additions & 0 deletions model/API.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -1332,6 +1332,11 @@ public static function getSearchParamValues($params, $param) {
// Separate into boolean OR parts
$parts = preg_split("/\s+\|\|\s+/", $val);

// Replace \|| with || to allow for tags with literal '||'.
$parts = array_map(function ($part) {
return str_replace("\||", "||", $part);
}, $parts);

$val = array(
'negation' => $negation,
'values' => $parts
Expand Down

0 comments on commit 0bf6cdd

Please sign in to comment.