Bug 266866 - Dash character in character range breaks <input> pattern regex
Summary: Dash character in character range breaks <input> pattern regex
Status: RESOLVED INVALID
Alias: None
Product: WebKit
Classification: Unclassified
Component: Forms (show other bugs)
Version: Safari 17
Hardware: Mac (Apple Silicon) macOS 14
: P2 Major
Assignee: Nobody
URL:
Keywords: BrowserCompat, InRadar
Depends on:
Blocks:
 
Reported: 2023-12-24 09:48 PST by Ian Timothy
Modified: 2023-12-25 07:27 PST (History)
9 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ian Timothy 2023-12-24 09:48:30 PST
OVERVIEW

When the regex of a <input> pattern contains a character range with a actual dash character (not a range operator), the validation for the form element is always true. Dash characters recognized as range operators are not an issue (like: [0-9]), only dash characters recognized as an actual character in a set (like: [0-9-]).

This is a regression because it works as expected on older versions.

Is similar to, if not same as:
https://github.com/GoogleChrome/chromium-dashboard/issues/3106


STEPS TO REPRODUCE

i = document.createElement('input');
i.value = 'asdf';

i.pattern = '^[0-9-]{4}$';
v1 = i.checkValidity();   // returns true instead of false

i.pattern = '^[0-9]{4}$';
v2 = i.checkValidity();   // returns false as expected

console.log(v1, v2);


ACTUAL RESULTS

Safari 17:
true - false

Safari 15:
false - false


EXPECTED RESULTS

false - false
Comment 1 Karl Dubost 2023-12-24 19:57:24 PST
I wonder if it could be because of this change by Anne
https://searchfox.org/wubkat/diff/092303e2abb1e89254f64b301953ac0fbf36c681/Source/WebCore/html/BaseTextInputType.cpp#43
Comment 2 Radar WebKit Bug Importer 2023-12-24 19:57:34 PST
<rdar://problem/120106089>
Comment 3 Anne van Kesteren 2023-12-25 07:27:52 PST
Hey Ian, thank you for reporting this. This is an intentional change in behavior: see bug 251675.

You can fix this by escaping - as \\-, although if you set it from script you might need even more backslashes. I suspect \\\\-.

As such closing this as INVALID.