Skip to content

Commit

Permalink
allow to escape || character with \|| for tags get or delete
Browse files Browse the repository at this point in the history
Replace \|| with || during arguments parsing. If an item is tagged 'This is something || Or other', to get items with this tag or delete this tag, || can be escaped like this tags='This is something \|| Or other'.
Fixes: 118
Fixes: 112
  • Loading branch information
abaevbog committed Jun 14, 2023
1 parent 2cf66c3 commit c53dae2
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 c53dae2

Please sign in to comment.