Knockout-Contrib / Knockout-Contrib/Knockout-Validation

Pattern anchor

Open
#664 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
1k
Forks
366
PR merge metrics
No merged PRs in 30d

Description

When reading pattern from HTML it is used directly as a regular expression, which is not correct. The spec says

The compiled pattern regular expression, when matched against a string, must have its start anchored to the start of the string and its end anchored to the end of the string.

This implies that the regular expression language used for this attribute is the same as that used in JavaScript, except that the pattern attribute is matched against the entire value, not just any subset (somewhat as if it implied a ^(?: at the start of the pattern and a )$ at the end).

That means native validation using pattern="\d{5}" only accepts exactly five numbers. But knockout validation will use this as a regular expression, which will accept anything that contains five numbers aynwhere. E.g. foo12345bar.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the validation path that reads the HTML pattern attribute and compare its matching behavior with native whole-value validation. Reproduce the issue with pattern="\d{5}" and a value such as foo12345bar; done means the value is rejected unless it is exactly five digits.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.