Skip to content

Commit c9689eb

Browse files
committed
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
1 parent 2cf66c3 commit c9689eb

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

controllers/TagsController.php

+4
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,10 @@ public function tags() {
186186
// Filter for specific tags with "?tag=foo || bar"
187187
$tagNames = !empty($this->queryParams['tag'])
188188
? explode(' || ', $this->queryParams['tag']): array();
189+
// Replace \|| with || to allow for tags with literal '||'.
190+
$tagNames = array_map(function ($name) {
191+
return str_replace("\||", "||", $name);
192+
}, $tagNames);
189193
Zotero_DB::beginTransaction();
190194
foreach ($tagNames as $tagName) {
191195
$tagIDs = Zotero_Tags::getIDs($this->objectLibraryID, $tagName);

model/API.inc.php

+5
Original file line numberDiff line numberDiff line change
@@ -1332,6 +1332,11 @@ public static function getSearchParamValues($params, $param) {
13321332
// Separate into boolean OR parts
13331333
$parts = preg_split("/\s+\|\|\s+/", $val);
13341334

1335+
// Replace \|| with || to allow for tags with literal '||'.
1336+
$parts = array_map(function ($part) {
1337+
return str_replace("\||", "||", $part);
1338+
}, $parts);
1339+
13351340
$val = array(
13361341
'negation' => $negation,
13371342
'values' => $parts

0 commit comments

Comments
 (0)