websanova / js-url

url() - A simple, lightweight url parser for JavaScript
http://www.websanova.com
MIT License
1.93k stars 204 forks source link

can not got query param when there's multiple ? eg: http://xxx.com?k=v#/a/b?k2=v2 #40

Closed xiwc closed 9 years ago

websanova commented 9 years ago

Not sure what you're asking:

`console.log(window.url('?', 'http://xxx.com?k=v#/a/b?k2=v2')); // {k: "v"}`
`console.log(window.url('#', 'http://xxx.com?k=v#/a/b?k2=v2')); // {/a/b?k2: "v2"}`

This is behaving properly. It will parse at the first ?. Also the second one is after the # so it's separate parsing there which is not supported in the script.

You may have to do some manual parsing:

var hash = str.split('#')[1]; //  '/a/b?k2=v2'

console.log(window.url('?',hash)); // {k2: "v2"}
console.log(window.url('/', hash)); // ["a", "b"]
xiwc commented 9 years ago

var s = 'http://example.com/index.html#/project/ff8081815070fa4c0150734af2871482/task-pane?code=c8125974b528718ef9d29f2ac852fe18&accessToken=RUwwZjJvdWFiOWtXa2F6NnV1c1BiWTg4LzFKQXo3ekVZYlBIYU9raTFxM2M5MWtTK3FNV0dFcEpoUnV4b3pmTVdTL1ltcVExY3M4WncvT2t2TlkyUU5YUklXbVNpN0ZCV3p1TTJYZlNEMVVRVWtYT2kveHMwbnZoQUcwM1ZGckk=';

url('#', s);

"/project/ff8081815070fa4c0150734af2871482/task-pane?code=c8125974b528718ef9d29f2ac852fe18&accessToken=RUwwZjJvdWFiOWtXa2F6NnV1c1BiWTg4LzFKQXo3ekVZYlBIYU9raTFxM2M5MWtTK3FNV0dFcEpoUnV4b3pmTVdTL1ltcVExY3M4WncvT2t2TlkyUU5YUklXbVNpN0ZCV3p1TTJYZlNEMVVRVWtYT2kveHMwbnZoQUcwM1ZGckk="

but i only want to get /project/ff8081815070fa4c0150734af2871482/task-pane without query string.

websanova commented 9 years ago

Try url('/', s); On Oct 17, 2015 10:19 AM, "xiwc" notifications@github.com wrote:

var s = ' http://example.com/index.html#/project/ff8081815070fa4c0150734af2871482/task-pane?code=c8125974b528718ef9d29f2ac852fe18&accessToken=RUwwZjJvdWFiOWtXa2F6NnV1c1BiWTg4LzFKQXo3ekVZYlBIYU9raTFxM2M5MWtTK3FNV0dFcEpoUnV4b3pmTVdTL1ltcVExY3M4WncvT2t2TlkyUU5YUklXbVNpN0ZCV3p1TTJYZlNEMVVRVWtYT2kveHMwbnZoQUcwM1ZGckk= ';

url('#', s);

"/project/ff8081815070fa4c0150734af2871482/task-pane?code=c8125974b528718ef9d29f2ac852fe18&accessToken=RUwwZjJvdWFiOWtXa2F6NnV1c1BiWTg4LzFKQXo3ekVZYlBIYU9raTFxM2M5MWtTK3FNV0dFcEpoUnV4b3pmTVdTL1ltcVExY3M4WncvT2t2TlkyUU5YUklXbVNpN0ZCV3p1TTJYZlNEMVVRVWtYT2kveHMwbnZoQUcwM1ZGckk="

but i only want to get /project/ff8081815070fa4c0150734af2871482/task-pane without query string.

— Reply to this email directly or view it on GitHub https://github.com/websanova/js-url/issues/40#issuecomment-148881502.

xiwc commented 9 years ago

does not work: image

my using url version: image

websanova commented 9 years ago

Can you upgrade to latest version? On Oct 17, 2015 10:37, "xiwc" notifications@github.com wrote:

does not work: [image: image] https://cloud.githubusercontent.com/assets/8816203/10556823/5d37f150-74c3-11e5-812d-79a9754da70b.png

my using url version: [image: image] https://cloud.githubusercontent.com/assets/8816203/10556824/66931824-74c3-11e5-8d34-5fdc69d959ea.png

— Reply to this email directly or view it on GitHub https://github.com/websanova/js-url/issues/40#issuecomment-148882923.

xiwc commented 9 years ago

Very 3ks, i saw the 2.x version, i will try.