Skip to content

Commit

Permalink
validateIri to Reject "http://" URL (#1158)
Browse files Browse the repository at this point in the history
  • Loading branch information
timmyteo committed Jun 10, 2024
1 parent 43c5bbf commit 4905b81
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
2 changes: 1 addition & 1 deletion types/utils.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 18 additions & 6 deletions utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -10674,14 +10674,26 @@ export function parseMakeDFile(dfile) {
*
*/
export function isValidIriReference(iri) {
const result = validateIri(iri, IriValidationStrategy.Strict);
let iriIsValid = true;
const validateIriResult = validateIri(iri, IriValidationStrategy.Strict);

if (result instanceof Error) {
if (DEBUG_MODE) {
console.log(`IRI failed validation ${iri}`);
if (validateIriResult instanceof Error) {
iriIsValid = false;
} else if (iri.toLocaleLowerCase().startsWith("http")) {
try {
new URL(iri);
} catch (error) {
iriIsValid = false;
}
return false;
}

return true;
if (iriIsValid) {
return true;
}

if (DEBUG_MODE) {
console.log(`IRI failed validation ${iri}`);
}

return false;
}
6 changes: 6 additions & 0 deletions utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4102,6 +4102,12 @@ test.each([
["http://gitlab.com/behat-chrome/chrome-mink-driver.git", true],
["git+https://github.com/Alex-D/check-disk-space.git", true],
["UNKNOWN", false],
["http://", false],
["http", false],
["https", false],
["https://", false],
["http://www", true],
["http://www.", true],
])("isValidIriReference tests: %s", (url, isValid) => {
expect(isValidIriReference(url)).toBe(isValid);
});

0 comments on commit 4905b81

Please sign in to comment.