Skip to content

Commit 234e906

Browse files
committed
empty share string now correctly does not include "#?"
1 parent 71ca286 commit 234e906

File tree

4 files changed

+20
-9
lines changed

4 files changed

+20
-9
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ Parts of the URL:
4444
Where `nose?name=bob` is the **fragment**, `nose` is the **fragment anchor**,
4545
and `?name=bob` is the **fragment query**.
4646

47+
For more complete naming of URI's see [FileVer][FileVer] (and in the future
48+
package "Cyphrme/URIPath").
49+
4750
In this example, since the query parameter and the fragment query parameter have
4851
the same key name of "name", the value of "bob" will take precedence over
4952
the value "ferret".

urlform.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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
*/
641642
function 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
*/
684688
function 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

urlform.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

urlform.min.js.map

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)