diff --git a/README.md b/README.md index c4a4b3d..ad9d26e 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ This script does not support: This is a JavaScript module that exports: [`URI`](#uri) (default), [`SegmentedString`](#segmentedstring), [`isDNSDomain`](#isdnsdomain), [`parseMailbox`](#parsemailbox) -[Try it on JSFiddle](https://jsfiddle.net/wizard04/896dmhga/) +[Try it on JSFiddle](https://jsfiddle.net/wizard04/evxog8r2/1/) --- diff --git a/demo/demo.htm b/demo/demo.htm new file mode 100644 index 0000000..93e66c9 --- /dev/null +++ b/demo/demo.htm @@ -0,0 +1,6 @@ +
+ +
+
+
+ \ No newline at end of file diff --git a/demo/demo.js b/demo/demo.js new file mode 100644 index 0000000..b0c9acc --- /dev/null +++ b/demo/demo.js @@ -0,0 +1,46 @@ +import URI, {isDNSDomain, parseMailbox} from "https://cdn.jsdelivr.net/gh/wizard04wsu/URI_Parsing@jsfiddle-demo/src/uri_parsing.mjs" + +document.getElementById("parse_scheme").addEventListener("click", ()=>{ + let val = document.getElementById("uri").value; + console.group("scheme"); + try{ + let obj = URI(val); + console.log("--> "+obj.toString()); + console.log(obj); + }catch(e){ + if(e instanceof URIError) console.error(e.message); + else throw e; + }finally{ + console.groupEnd(); + } +}, false); + +document.getElementById("parse_generic").addEventListener("click", ()=>{ + let val = document.getElementById("uri").value; + console.group("generic"); + try{ + let obj = URI.parse(val) + console.log("--> "+obj.toString()); + console.log(obj); + }catch(e){ + if(e instanceof URIError) console.error(e.message); + else throw e; + }finally{ + console.groupEnd(); + } +}, false); + +document.getElementById("parse_mailbox").addEventListener("click", ()=>{ + let val = document.getElementById("email").value; + console.group("email"); + try{ + let obj = parseMailbox(val); + console.log("--> "+obj.toString()); + console.log(obj); + }catch(e){ + if(e instanceof URIError) console.log(e.message); + else throw e; + }finally{ + console.groupEnd(); + } +}, false); diff --git a/src/uri_parsing.mjs b/src/uri_parsing.mjs index c20dc8d..e801389 100644 --- a/src/uri_parsing.mjs +++ b/src/uri_parsing.mjs @@ -273,24 +273,27 @@ URI.schemeParser = { p.to = p.path ? splitEmailAddresses(p.path) : []; - let headers = p.query.pairs || []; + let headers = p.query.pairs ? p.query.pairs.map(p=>{return { + name: decodeURIComponent(p.key), + value: p.value + }}) : []; for(let i=0; i