Skip to content

Commit

Permalink
Allow whitespace in pidcode strings.
Browse files Browse the repository at this point in the history
So `1 2 3 4` is valid pidcode, for `1,2,3,4` or `Q1c`.
And allow pidcode as a parameter for `p`.
  • Loading branch information
kohler committed Sep 18, 2023
1 parent 36d36c6 commit 9f090c8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/searchselection.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
// searchselection.php -- HotCRP helper class for paper selections
// Copyright (c) 2006-2022 Eddie Kohler; see LICENSE.
// Copyright (c) 2006-2023 Eddie Kohler; see LICENSE.

class SearchSelection {
/** @var list<int> */
Expand Down Expand Up @@ -32,7 +32,7 @@ static function make($qreq, Contact $user = null, $key = null) {
} else if ($qreq->get($key) === "all") {
$ps = $user ? (new PaperSearch($user, $qreq))->sorted_paper_ids() : null;
} else if ($qreq->has($key)) {
$ps = preg_split('/\s+/', $qreq->get($key));
$ps = SessionList::decode_ids($qreq->get($key));
} else {
$ps = null;
}
Expand Down
15 changes: 9 additions & 6 deletions src/sessionlist.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
// sessionlist.php -- HotCRP helper class for lists carried across pageloads
// Copyright (c) 2006-2022 Eddie Kohler; see LICENSE.
// Copyright (c) 2006-2023 Eddie Kohler; see LICENSE.

class SessionList {
/** @var string */
Expand Down Expand Up @@ -106,15 +106,15 @@ static function decode_ids($s) {
} else if ($ch >= 117 && $ch <= 120) { // u-x
$next += ($ch - 116) * 8 * $sign;
continue;
} else if ($ch === 113 || $ch === 114 || $ch === 116) {
} else if ($ch === 113 || $ch === 114 || $ch === 116) { // qrt
$j = 0;
while ($i !== $l && ctype_digit($s[$i])) {
$j = 10 * $j + ord($s[$i]) - 48;
++$i;
}
if ($ch === 113) {
if ($ch === 113) { // q
$add0 = $j;
} else if ($ch === 114) {
} else if ($ch === 114) { // r
$skip = $j;
} else {
$skip = -$j;
Expand All @@ -133,8 +133,11 @@ static function decode_ids($s) {
} else if ($ch === 81 && $i === 1) { // Q
$include_after = true;
continue;
} else if (($ch < 48 || $ch > 57) && $ch !== 115 && $ch !== 91 && $ch !== 93
&& $ch !== 35 && $ch !== 39 && $ch !== 44) {
} else if (($ch >= 9 && $ch <= 13) || $ch === 32
|| $ch === 35 || $ch === 39 || $ch === 44
|| $ch === 91 || $ch === 93 || $ch === 115) {
// \s # ' , [ ] s : ignore
} else {
return null;
}

Expand Down
2 changes: 2 additions & 0 deletions test/t_unit.php
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,9 @@ function test_session_list_ids() {
xassert_eqq(json_decode("[1,2,3-4,5,6-10,11]"), null);

xassert_eqq(SessionList::decode_ids("[1-2]"), [1,2]);
xassert_eqq(SessionList::decode_ids("1 2"), [1,2]);
xassert_eqq(SessionList::decode_ids("[1,2,3-4,5,6-10,11]"), [1,2,3,4,5,6,7,8,9,10,11]);
xassert_eqq(SessionList::decode_ids("1 2 3 4 5 6 7 8 9 10 11"), [1,2,3,4,5,6,7,8,9,10,11]);
xassert_eqq(SessionList::decode_ids(SessionList::encode_ids([1,2])), [1,2]);
xassert_eqq(SessionList::decode_ids(SessionList::encode_ids([1,2,3,4,5,6,7,8,9,10,11])), [1,2,3,4,5,6,7,8,9,10,11]);
xassert_eqq(SessionList::decode_ids(SessionList::encode_ids([1,3,5,7,9,10,11])), [1,3,5,7,9,10,11]);
Expand Down

0 comments on commit 9f090c8

Please sign in to comment.