You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Sep 25, 2025. It is now read-only.
Repository navigation
This repository was archived by the owner on Sep 25, 2025. It is now read-only.
Validate URL Fields like events.event_url and events.video_url #430
What are the requirements? What kind of input do we want to accept and which should be rejected?
To me, new URL() will generally check on valid URL format. The point came up, that some protocols (like javascript:) would pass, too. So there needs to be additional checks.
Another argument I've read where „URLs” without a domain (e.g. freecodecamp.org), which should be accepted.
If the language or framework doesn't already have something built-in for our use case, then I believe any code that aims to match RFC 2396 would get us close.
In PHP this involves a core method filter_var($url, FILTER_VALIDATE_URL) . StackOverflow comments suggest RFC 2396 doesn't check the protocol, so we'd have to manually check for https:// or http:// if that's a limitation.
@vkWeb I assume that's using HTML 5 validation on the front-end and we'd just not worry about older browsers.
I could get behind that too idea.
I can't imagine the output won't be sanitized by the framework, but that's certainly something we'll want for any user provided content that's printed back to the browser.
Even though the valid-url seems to be dead (while having 2M weekly downloads), it still works just fine and this is more of a nice to have than a required feature IMO.
For the MVP we just need to be able to show a small red error that there is something wrong, nothing special.
@Ravichandra-C if you think it would be easier with the Regex you linked you can use that.
@allella@Zeko369@ojeytonwilliams, Can I use class-validator module decorators for fields to add the @isurl Restriction in the Mutation instead of writing a custom validator? I also saw that type graphql validations are disabled in server/src/app.ts. Could you please let me know if there any reason for that? and Can I enable them?
Activity
Ryuno-Ki commentedon Nov 1, 2020
What are the requirements? What kind of input do we want to accept and which should be rejected?
To me,
new URL()will generally check on valid URL format. The point came up, that some protocols (likejavascript:) would pass, too. So there needs to be additional checks.Another argument I've read where „URLs” without a domain (e.g. freecodecamp.org), which should be accepted.
allella commentedon Nov 2, 2020
If the language or framework doesn't already have something built-in for our use case, then I believe any code that aims to match RFC 2396 would get us close.
In PHP this involves a core method
filter_var($url, FILTER_VALIDATE_URL). StackOverflow comments suggest RFC 2396 doesn't check the protocol, so we'd have to manually check for https:// or http:// if that's a limitation.vkWeb commentedon Nov 2, 2020
@Ryuno-Ki does the framework escapes the user input?
If yes then simply using
input type urlis the best way forward.Else we need to think more.
allella commentedon Nov 2, 2020
@vkWeb I assume that's using HTML 5 validation on the front-end and we'd just not worry about older browsers.
I could get behind that too idea.
I can't imagine the output won't be sanitized by the framework, but that's certainly something we'll want for any user provided content that's printed back to the browser.
allella commentedon Nov 2, 2020
And/or, I'm not sure if this is active, but a package like https://www.npmjs.com/package/valid-url would seem to do the job of validating the form input.
Ravichandra-C commentedon Sep 5, 2021
@allella Looks like valid-url is not active anymore.
Can we implement something like this?
https://github.com/adrienv1520/node-uri#checkuriuri
or Is it enough if we just parse the URI and then check if the some parts of the URI are not empty?
Can we parse it as shown in the gist?
https://gist.github.com/curtisz/11139b2cfcaef4a261e0
allella commentedon Sep 6, 2021
@Zeko369 do you have a suggestion on using a node package vs a regex snippet?
Zeko369 commentedon Sep 10, 2021
Even though the
valid-urlseems to be dead (while having 2M weekly downloads), it still works just fine and this is more of anice to havethan a required feature IMO.For the MVP we just need to be able to show a small red error that there is something wrong, nothing special.
@Ravichandra-C if you think it would be easier with the Regex you linked you can use that.
Ravichandra-C commentedon Sep 16, 2021
@allella @Zeko369 @ojeytonwilliams, Can I use class-validator module decorators for fields to add the @isurl Restriction in the Mutation instead of writing a custom validator? I also saw that type graphql validations are disabled in server/src/app.ts. Could you please let me know if there any reason for that? and Can I enable them?
Zeko369 commentedon Sep 16, 2021
YES, enable them in
app.tsand use them here.I'd just do
IsUrlabove Field to make it more consistent and nicer looking, but that's just a personal preference