Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2c26172

Browse files
committed
Fix: accept wider range of protocols
1 parent 626ad11 commit 2c26172

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
## [Unreleased]
22

3+
- Fix: `url` decoder now also accepts a wider range of protocol lengths, now accepting
4+
e.g. at:// and postgresql:// URLs
5+
36
## [2.7.1] - 2025-08-01
47

58
- Fix: `dateString` decoder is now properly exported at the top-level

src/strings.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { either } from './unions';
1515
* \5 - the path (optional)
1616
*/
1717
const url_re =
18-
/^([A-Za-z]{3,9}(?:[+][A-Za-z]{3,9})?):\/\/(?:([-;:&=+$,\w]+)@)?(?:([A-Za-z0-9.-]+)(?::([0-9]{2,5}))?)(\/(?:[-+~%/.,\w]*)?(?:\?[-+=&;%@.,/\w]*)?(?:#[.,!/\w]*)?)?$/;
18+
/^([A-Za-z]{2,12}(?:[+][A-Za-z]{2,12})?):\/\/(?:([-;:&=+$,\w]+)@)?(?:([A-Za-z0-9.-]+)(?::([0-9]{2,5}))?)(\/(?:[-+~%/.,\w]*)?(?:\?[-+=&;%@.,/\w]*)?(?:#[.,!/\w]*)?)?$/;
1919

2020
/**
2121
* Accepts and returns strings.

test/strings.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,6 @@ describe('url', () => {
130130
const decoder = url;
131131

132132
test('valid', () => {
133-
expect(decoder.verify(new URL('https://nvie.com/')).toString()).toEqual(
134-
'https://nvie.com/',
135-
);
136133
expect(decoder.verify('https://nvie.com').toString()).toEqual('https://nvie.com/');
137134
expect(decoder.verify('https://example.com/foo?q=foo/bar').toString()).toBe(
138135
'https://example.com/foo?q=foo/bar',
@@ -143,6 +140,10 @@ describe('url', () => {
143140
expect(decoder.verify('https://res.example.com/a_b,c_1d/foo.svg').toString()).toBe(
144141
'https://res.example.com/a_b,c_1d/foo.svg',
145142
);
143+
expect(decoder.verify('postgresql://localhost/db').toString()).toEqual(
144+
'postgresql://localhost/db',
145+
);
146+
expect(decoder.verify('at://localhost/db').toString()).toEqual('at://localhost/db');
146147
});
147148

148149
test('custom URL schemes', () => {

0 commit comments

Comments
 (0)