From c9689eb9ba4fead4b875915ab6f91bc2078a1b2e Mon Sep 17 00:00:00 2001 From: Bogdan Abaev Date: Wed, 14 Jun 2023 15:34:42 -0400 Subject: [PATCH] allow to escape || character with \|| for tags get or delete 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 --- controllers/TagsController.php | 4 ++++ model/API.inc.php | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/controllers/TagsController.php b/controllers/TagsController.php index dad6a4820..abb1a7c39 100644 --- a/controllers/TagsController.php +++ b/controllers/TagsController.php @@ -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); diff --git a/model/API.inc.php b/model/API.inc.php index 863104a30..da3985389 100644 --- a/model/API.inc.php +++ b/model/API.inc.php @@ -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