Skip to content

Commit a47a6dd

Browse files
committed
Strings should not be uri format if they don’t have a hostname
1 parent 1b79feb commit a47a6dd

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/formats/uri.ts

+4
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ export function inferUri(value: string): JSONURIFormat | undefined {
9696
try {
9797
const url = new URL(value);
9898

99+
if (url.hostname === "") {
100+
return undefined;
101+
}
102+
99103
// Get mimetype from extension
100104
const ext = url.pathname.split(".").pop();
101105
const mimeType = lookupMimeType(ext);

tests/bugs.test.ts

+12
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,15 @@ test("https://www.mattaitken.com is a string with format of uri", () => {
99
},
1010
});
1111
});
12+
13+
test(`"creditCardNumber:NullValue,\ncreditCardExpirationMonth:NullValue,\ncreditCardExpirationYear:NullValue,\ncardSecurityCode:NullValue,\ncreditCardState:NullValue,\n" is a string with no format`, () => {
14+
expect(
15+
inferType(
16+
"creditCardNumber:NullValue,\ncreditCardExpirationMonth:NullValue,\ncreditCardExpirationYear:NullValue,\ncardSecurityCode:NullValue,\ncreditCardState:NullValue,\n",
17+
),
18+
).toEqual({
19+
name: "string",
20+
value:
21+
"creditCardNumber:NullValue,\ncreditCardExpirationMonth:NullValue,\ncreditCardExpirationYear:NullValue,\ncardSecurityCode:NullValue,\ncreditCardState:NullValue,\n",
22+
});
23+
});

0 commit comments

Comments
 (0)