@@ -623,6 +623,7 @@ async function ShareURI(formOptions) {
623623 q . query . pairs [ fp . name ] = value
624624 }
625625 }
626+
626627 u . search = buildQueryString ( q . query . pairs , q . query . extras , formOptions ) // Escapes values (like encodeURIComponent)
627628 u . hash = fragmentToString ( q . fragment , formOptions ) // Escapes values (like encodeURIComponent)
628629 // console.log(q.query.pairs, q.fragment, u.href);
@@ -639,11 +640,14 @@ getURIBase returns the URI Base (see package Cyphrme/URIPath)
639640@returns {URL } Javascript URL object.
640641*/
641642function getURIBase ( ) {
642- // `u` is the current URL. `window.location.pathname` incorrectly includes query but will be
643- // replaced by `u.search = ""`. Ideally, Javascript would provide an way to get
644- // the URI base which does not include any quag component. (See package `Cyphrme/URIPath`)
643+ // `u` is the current URL. `window.location.pathname` _incorrectly_ includes
644+ // query but will be replaced by `u.search = ""`. This is done also for hash
645+ // to follow the same form. Ideally, Javascript would provide an way to get
646+ // the URI base which does not include any quag component. (See package
647+ // `Cyphrme/URIPath`)
645648 var u = new URL ( window . location . origin + window . location . pathname )
646649 u . search = ""
650+ u . hash = ""
647651 return u
648652}
649653
@@ -665,7 +669,7 @@ function fragmentToString(fragment, formOptions) {
665669 let fqs = "#" + fragment . before
666670 fqs += buildQueryString ( fragment . pairs , fragment . extras , formOptions )
667671 fqs += fragment . after
668- if ( fqs == "#" ) { // Return empty string if fragment is empty.
672+ if ( fqs == "#" || fqs == "#?" ) { // Return empty string if fragment is empty.
669673 return ""
670674 }
671675 return fqs
@@ -683,11 +687,11 @@ value=true or value=false, otherwise empty (`value=""`) are omitted.
683687*/
684688function buildQueryString ( kv , extrasKV , formOptions ) {
685689 //console.log("buildQueryString", kv)
686- let qs = ""
690+ let qs = "? "
687691 let firstParam = true ;
692+
688693 // kv
689694 if ( Object . keys ( kv ) . length !== 0 ) {
690- qs += "?" //start fragment query delimiter ("?")
691695 for ( let key in kv ) {
692696 let value = kv [ key ]
693697 if ( value === "" ) {
@@ -716,6 +720,10 @@ function buildQueryString(kv, extrasKV, formOptions) {
716720 qs += e + "=" + extrasKV [ e ]
717721 }
718722 }
723+
724+ if ( qs == "?" ) { // Return empty string if fragment is empty.
725+ return ""
726+ }
719727 return qs
720728}
721729
0 commit comments