You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Assert::uuid(...) returns false positives on UUIDs with trailing newlines
Test Cases:
Assert::uuid("c9df9150-6536-42e0-802a-266f7ccc189c"); // Valid as expected
Assert::uuid("c9df9150-6536-42e0-802a-266f7ccc189c\r"); // Invalid as expected
Assert::uuid("c9df9150-6536-42e0-802a-266f7ccc189c\r\n"); // Invalid as expected
Assert::uuid("c9df9150-6536-42e0-802a-266f7ccc189c\n"); // Currently Valid (incorrect)
if (!\preg_match('/^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$/', $value)) {
The regular expression above checks if the test subject starts and ends with a UUID (by using ^ and $). However, the $ anchor not only anchors the end of the string, but also an immediate newline character. (as stated here)
Proposed Solution:
To prevent false positives, we can make use of the PCRE_DOLLAR_ENDONLY flag (D) that will constraint the $ anchor to match the end of the string only, not a new character.
- if (!\preg_match('/^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$/', $value)) { + if (!\preg_match('/^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$/D', $value)) {
The text was updated successfully, but these errors were encountered:
Assert::uuid(...)
returns false positives on UUIDs with trailing newlinesTest Cases:
Proposed Cause:
assert/src/Assert.php
Line 1982 in f23349f
The regular expression above checks if the test subject starts and ends with a UUID (by using
^
and$
). However, the$
anchor not only anchors the end of the string, but also an immediate newline character. (as stated here)Proposed Solution:
To prevent false positives, we can make use of the
PCRE_DOLLAR_ENDONLY
flag (D
) that will constraint the$
anchor to match the end of the string only, not a new character.The text was updated successfully, but these errors were encountered: