Skip to content

Commit 8cca839

Browse files
authored
Merge pull request #30 from nrps9909/codex/support-single-label-url-host
fix: support single-label URL hosts
1 parent 44f8f27 commit 8cca839

2 files changed

Lines changed: 34 additions & 1 deletion

File tree

‎src/rule/url.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export default () => {
5353
const tld = `(?:\\.(?:[a-z\\u00a1-\\uffff]{2,}))`;
5454
const port = '(?::\\d{2,5})?';
5555
const path = '(?:[/?#][^\\s"]*)?';
56-
const regex = `(?:${protocol}|www\\.)${auth}(?:localhost|${ipv4}|${ipv6}|${host}${domain}${tld})${port}${path}`;
56+
const regex = `(?:${protocol}|www\\.)${auth}(?:localhost|${ipv4}|${ipv6}|${host}(?:${domain}${tld})?)${port}${path}`;
5757
urlReg = new RegExp(`(?:^${regex}$)`, 'i');
5858
return urlReg;
5959
};

‎tests/url.spec.ts‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,39 @@ describe('url', () => {
3333
);
3434
});
3535

36+
it('works for single-label host url', done => {
37+
new Schema({
38+
v: {
39+
type: 'url',
40+
},
41+
}).validate(
42+
{
43+
v: 'http://fastapi:3000/mcp',
44+
},
45+
errors => {
46+
expect(errors).toBe(null);
47+
done();
48+
},
49+
);
50+
});
51+
52+
it('rejects invalid single-label host url', done => {
53+
new Schema({
54+
v: {
55+
type: 'url',
56+
},
57+
}).validate(
58+
{
59+
v: 'http://-fastapi:3000/mcp',
60+
},
61+
errors => {
62+
expect(errors).toHaveLength(1);
63+
expect(errors[0].message).toBe('v is not a valid url');
64+
done();
65+
},
66+
);
67+
});
68+
3669
it('works for required empty string', done => {
3770
new Schema({
3871
v: {

0 commit comments

Comments
 (0)