Skip to content

Fix URL validator scheme regex to allow RFC 1738 characters#885

Closed
bysiber wants to merge 1 commit intopallets-eco:mainfrom
bysiber:fix-url-validator-scheme-regex
Closed

Fix URL validator scheme regex to allow RFC 1738 characters#885
bysiber wants to merge 1 commit intopallets-eco:mainfrom
bysiber:fix-url-validator-scheme-regex

Conversation

@bysiber
Copy link

@bysiber bysiber commented Feb 21, 2026

Fixes #841.

The URL validator regex for the scheme part uses ^[a-z]+://, which only accepts lowercase letters. Per RFC 1738 §2.1, scheme names can also contain digits, +, ., and - after the initial letter. This means URLs with schemes like com.example.app://callback (common in OAuth custom URI schemes per RFC 8252 §7.1) are incorrectly rejected.

Changed the scheme regex to ^[a-z][a-z0-9+\-.]*:// to match the spec. Also added test cases covering schemes with digits, +, ., -, a complex dot-separated scheme, and a negative test for a scheme starting with a digit.

The URL validator regex only accepted lowercase letters in the scheme
(`^[a-z]+://`), but RFC 1738 allows digits, `+`, `.`, and `-` after
the first letter. This caused valid URLs like `com.example.app://callback`
to be rejected.

Changed the regex to `^[a-z][a-z0-9+\-.]*://` to match the RFC spec.
Added test cases for schemes containing these characters.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

URL validator has incorrect regexp range for scheme

2 participants