mirror of
https://github.com/vale981/tridactyl
synced 2025-03-05 17:41:40 -05:00
url_util: Fix #256.
This commit is contained in:
parent
e4231307ce
commit
df9451e83e
2 changed files with 9 additions and 1 deletions
|
@ -66,6 +66,12 @@ function test_parent() {
|
|||
["http://sub.example.com", "http://example.com/"],
|
||||
// subdom with path, leave subdom
|
||||
["http://sub.example.com/path", "http://sub.example.com/"],
|
||||
// trailing slash
|
||||
["http://sub.example.com/path/", "http://sub.example.com/"],
|
||||
// repeated slash
|
||||
["http://example.com/path//", "http://example.com/"],
|
||||
// repeated slash
|
||||
["http://example.com//path//", "http://example.com/"],
|
||||
]
|
||||
|
||||
for (let [url, exp_parent] of cases) {
|
||||
|
|
|
@ -80,7 +80,9 @@ export function getUrlParent(url, count = 1) {
|
|||
|
||||
// pathname always starts '/'
|
||||
if (parent.pathname !== '/') {
|
||||
let path = parent.pathname.substring(1).split('/')
|
||||
// Split on '/' and remove empty substrings
|
||||
// (handles initial and trailing slashes, repeated slashes, etc.)
|
||||
let path = parent.pathname.split('/').filter(sub => sub !== "")
|
||||
path.pop()
|
||||
parent.pathname = path.join('/')
|
||||
return gup(parent, count - 1)
|
||||
|
|
Loading…
Add table
Reference in a new issue