Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

validateIri to Reject "http://" URL #1158

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
1 change: 1 addition & 0 deletions utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4102,6 +4102,7 @@ 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],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add more test cases like

empty string
http
https
https://
http://www
http://www.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

])("isValidIriReference tests: %s", (url, isValid) => {
expect(isValidIriReference(url)).toBe(isValid);
});
Loading