Skip to content

Commit 3000e27

Browse files
committed
no more regex
1 parent dc5f3fb commit 3000e27

File tree

4 files changed

+23
-33
lines changed

4 files changed

+23
-33
lines changed

resources/lib/UnityHTTPD.php

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -341,46 +341,36 @@ public static function clearMessages()
341341

342342
private static function getMessageIndex(
343343
UnityHTTPDMessageLevel $level,
344-
string $title_regex,
345-
string $body_regex,
344+
string $title,
345+
string $body,
346346
) {
347347
$messages = self::getMessages();
348348
$error_msg = sprintf(
349-
"message(level='%s' title_regex='%s' body_regex='%s'), not found. found messages: %s",
349+
"message(level='%s' title='%s' body='%s'), not found. found messages: %s",
350350
$level->value,
351-
$title_regex,
352-
$body_regex,
351+
$title,
352+
$body,
353353
jsonEncode($messages),
354354
);
355355
foreach ($messages as $i => $message) {
356-
if (
357-
preg_match($title_regex, $message[0]) &&
358-
preg_match($body_regex, $message[1]) &&
359-
$level == $message[2]
360-
) {
356+
if ($title == $message[0] && $body == $message[1] && $level == $message[2]) {
361357
return $i;
362358
}
363359
}
364360
throw new UnityHTTPDMessageNotFoundException($error_msg);
365361
}
366362

367-
/* returns the 1st message that matches criteria or throws UnityHTTPDMessageNotFoundException */
368-
public static function getMessage(
369-
UnityHTTPDMessageLevel $level,
370-
string $title_regex,
371-
string $body_regex,
372-
) {
373-
$index = self::getMessageIndex($level, $title_regex, $body_regex);
363+
/* returns the 1st message that matches or throws UnityHTTPDMessageNotFoundException */
364+
public static function getMessage(UnityHTTPDMessageLevel $level, string $title, string $body)
365+
{
366+
$index = self::getMessageIndex($level, $title, $body);
374367
return $_SESSION["messages"][$index];
375368
}
376369

377-
/* deletes the 1st message that matches criteria or throws UnityHTTPDMessageNotFoundException */
378-
public static function deleteMessage(
379-
UnityHTTPDMessageLevel $level,
380-
string $title_regex,
381-
string $body_regex,
382-
) {
383-
$index = self::getMessageIndex($level, $title_regex, $body_regex);
370+
/* deletes the 1st message that matches or throws UnityHTTPDMessageNotFoundException */
371+
public static function deleteMessage(UnityHTTPDMessageLevel $level, string $title, string $body)
372+
{
373+
$index = self::getMessageIndex($level, $title, $body);
384374
unset($_SESSION["messages"][$index]);
385375
$_SESSION["messages"] = array_values($_SESSION["messages"]);
386376
}

resources/templates/header.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,8 @@
155155
method: 'POST',
156156
data: {
157157
'level': '%s',
158-
'title_regex': '/^%s$/',
159-
'body_regex': '/^%s$/',
158+
'title': '%s',
159+
'body': '%s',
160160
}
161161
});
162162
\"
@@ -169,8 +169,8 @@
169169
htmlspecialchars($title),
170170
htmlspecialchars($body),
171171
htmlspecialchars($level->value),
172-
preg_quote(htmlspecialchars($title), "/"),
173-
preg_quote(htmlspecialchars($body), "/"),
172+
htmlspecialchars($title),
173+
htmlspecialchars($body),
174174
);
175175
}
176176
if (

test/functional/DeleteMessageTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ public function testDeleteMessage(): void
2424
__DIR__ . "/../../webroot/panel/ajax/delete_message.php",
2525
[
2626
"level" => "debug",
27-
"title_regex" => "/^.*2$/",
28-
"body_regex" => "/^.*2$/",
27+
"title" => "foo2",
28+
"body" => "bar2",
2929
],
3030
enforce_PRG: false,
3131
);

webroot/panel/ajax/delete_message.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77

88
$level_str = UnityHTTPD::getPostData("level");
99
$level = UnityHTTPDMessageLevel::from($level_str);
10-
$title_regex = UnityHTTPD::getPostData("title_regex");
11-
$body_regex = UnityHTTPD::getPostData("body_regex");
12-
UnityHTTPD::deleteMessage($level, $title_regex, $body_regex);
10+
$title = UnityHTTPD::getPostData("title");
11+
$body = UnityHTTPD::getPostData("body");
12+
UnityHTTPD::deleteMessage($level, $title, $body);

0 commit comments

Comments
 (0)