-
Notifications
You must be signed in to change notification settings - Fork 125
jslt-152: parse-url error handling control #153
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
base: master
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -826,10 +826,42 @@ format-time(null, "yyyy-MM-dd") => null | |
|
|
||
| ## Miscellaneous functions | ||
|
|
||
| ### _parse-url(url) -> object_ | ||
| ### _parse-url(url, throwOnFailure?) -> object_ | ||
|
|
||
| Parses `url` and returns an object with keys [`scheme`, `userinfo`, `host`, `port` `path`, `query`, `parameters`, `fragment` ] | ||
|
|
||
| If the optional `throwOnFailure` argument is not specified invalid URLs will generate an exception. If `throwOnFailure` is set to `false` the `parse-url` returns | ||
| an object indicating an error occurred. | ||
|
|
||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to document the shape of that object, and have an example.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added some examples below but I agree we could add more documentation on the shape both when good and bad input
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated with more detaild examples. |
||
| #### Example of valid URL response | ||
|
|
||
| ```json | ||
| { | ||
| "host": "example.com", | ||
| "port": 8080, | ||
| "path": "/examples/", | ||
| "scheme": "https", | ||
| "query": "x=1&y=", | ||
| "parameters": { | ||
| "x": ["1"], | ||
| "y": [null] | ||
| }, | ||
| "fragment": "footer", | ||
| "userinfo": "myname:mypwd" | ||
| } | ||
| ``` | ||
|
|
||
| #### Example of invalid URL response with throwOnFailure=false | ||
|
|
||
| ```json | ||
| { | ||
| "error": "java.net.MalformedURLException", | ||
| "message": "no protocol: this-is-an-invalid-url", | ||
| "input": "this-is-an-invalid-url" | ||
| } | ||
| ``` | ||
|
|
||
| #### Examples | ||
| ``` | ||
| parse-url("http://example.com").scheme => "http" | ||
| parse-url("http://example.com").host => "example.com" | ||
|
|
@@ -841,4 +873,8 @@ parse-url("https://www.example.com/?aa=1&aa=2&bb=&cc").parameters.bb => [null] | |
| parse-url("https://www.example.com/?aa=1&aa=2&bb=&cc").parameters.cc => [null] | ||
| parse-url("ftp://username:password@host.com/").userinfo => "username:password" | ||
| parse-url("https://example.com:8443").port => 8443 | ||
|
|
||
| parse-url("this-is-an-invalid-url", false).error => "java.net.MalformedURLException" | ||
| parse-url("this-is-an-invalid-url", false).message => "no protocol: this-is-an-invalid-url" | ||
| parse-url("this-is-an-invalid-url", false).input => "this-is-an-invalid-url" | ||
| ``` | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need a test of what happens if the second argument is not a boolean. IMHO that should be considered an error: ie, throw an exception.
We also need a test of
nullhandling, with and without the second parameter. (Should have had anulltest already, sorry.) I thinknullinput should lead tonulloutput, regardless of the value of the second parameter.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am unsure how you typically tests for failures. Do you have an example? I looked in the query-tests.yaml and found no obvious cases to me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See
function-error-tests.jsonfor examples.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added tests