Skip to content

Commit ba617e4

Browse files
committed
Make isUrl stricter
1 parent c9f6aba commit ba617e4

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

cypress/integration/validation.js

+13
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,19 @@ describe('URLs validation', function() {
160160
cy.get('#errorMessage').should('have.text', 'Invalid URL in field "codeRepository": "foo"');
161161
});
162162

163+
it('errors on invalid URL that Javascript considers to be valid', function() {
164+
cy.get('#codemetaText').then((elem) =>
165+
elem.text(JSON.stringify({
166+
"@context": "https://doi.org/10.5063/schema/codemeta-2.0",
167+
"@type": "SoftwareSourceCode",
168+
"codeRepository": "foo: bar",
169+
}))
170+
);
171+
cy.get('#validateCodemeta').click();
172+
173+
cy.get('#errorMessage').should('have.text', 'Invalid URL in field "codeRepository": "foo: bar"');
174+
});
175+
163176
it('errors on non-string instead of URL', function() {
164177
cy.get('#codemetaText').then((elem) =>
165178
elem.text(JSON.stringify({

js/utils.js

+4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ function trimSpaces(s) {
2929
function isUrl(s) {
3030
try {
3131
const url = new URL(s);
32+
if (url.origin == "null") {
33+
// forbids "foo: bar" as a URL, for example
34+
return false;
35+
}
3236
return true;
3337
} catch (e) {
3438
return false;

0 commit comments

Comments
 (0)