window.location.search="" does nothing

Talk about code development, features, specific bugs, enhancements, patches, and similar things.
Forum rules
Please keep everything here strictly on-topic.
This board is meant for Pale Moon source code development related subjects only like code snippets, patches, specific bugs, git, the repositories, etc.

This is not for tech support! Please do not post tech support questions in the "Development" board!
Please make sure not to use this board for support questions. Please post issues with specific websites, extensions, etc. in the relevant boards for those topics.

Please keep things on-topic as this forum will be used for reference for Pale Moon development. Expect topics that aren't relevant as such to be moved or deleted.
dosse91

window.location.search="" does nothing

Unread post by dosse91 » 2019-01-30, 16:38

  • Windows 10 1809
  • Pale Moon 28.3.1 64 bit, installed
Changing the value of window.location.search is supposed to trigger a page reload, and it does, unless the new value is an empty string, in which case nothing happens, the old string is still there and the page doesn't reload.

To reproduce the problem:
  • Open any page
  • In the console, type window.location.search="anything", the page will reload and the new value will be assigned
  • Type window.location.serach="", the page won't reload and the old URL is still there
All other major browsers reload the page so I assume this is a bug.

User avatar
Moonchild
Pale Moon guru
Pale Moon guru
Posts: 35592
Joined: 2011-08-28, 17:27
Location: Motala, SE
Contact:

Re: window.location.search="" does nothing

Unread post by Moonchild » 2019-01-30, 19:59

Not responding to an empty string is deliberate.
Triggering a reload by passing empty strings to location.* setters can be abused so we don't respond to empty strings passed to .host, .hostname, .href, .protocol or .search

EDIT: What is the situation here, anyway? In what circumstances do you rely on this implied behavior, and why?
"Sometimes, the best way to get what you want is to be a good person." -- Louis Rossmann
"Seek wisdom, not knowledge. Knowledge is of the past; wisdom is of the future." -- Native American proverb
"Linux makes everything difficult." -- Lyceus Anubite

dosse91

Re: window.location.search="" does nothing

Unread post by dosse91 » 2019-01-31, 14:34

I discovered the problem while writing a piece of JS. I wanted to reload the page without the GET arguments that were passed previously, so I used window.location.search="" and it reloads the page. It works on all browsers but gets stuck on Pale Moon, and I traced it down to this.

If this isn't the proper way to do it, then what is it? Also, why is Pale Moon the only browser to do this?

User avatar
Moonchild
Pale Moon guru
Pale Moon guru
Posts: 35592
Joined: 2011-08-28, 17:27
Location: Motala, SE
Contact:

Re: window.location.search="" does nothing

Unread post by Moonchild » 2019-01-31, 20:04

To issue a reload, you can use location.reload()
dosse91 wrote:Also, why is Pale Moon the only browser to do this?
Because we're generally more security-aware in our development.

You may as well ask why we haven't accepted 3DES ciphers for quite a while now while other browsers happily keep accepting this old and insecure cipher, or why we've never accepted insecure protocol fallbacks for TLS while other browsers happily do so to "connect at all costs", and get the same answer.
"Sometimes, the best way to get what you want is to be a good person." -- Louis Rossmann
"Seek wisdom, not knowledge. Knowledge is of the past; wisdom is of the future." -- Native American proverb
"Linux makes everything difficult." -- Lyceus Anubite

dosse91

Re: window.location.search="" does nothing

Unread post by dosse91 » 2019-01-31, 20:18

location.reload() doesn't remove the GET arguments (or even the POST ones, it will display a warning).
The only way to do what I want on PM seems to be window.location=location.protocol+"//"+location.host+location.pathname;

User avatar
Moonchild
Pale Moon guru
Pale Moon guru
Posts: 35592
Joined: 2011-08-28, 17:27
Location: Motala, SE
Contact:

Re: window.location.search="" does nothing

Unread post by Moonchild » 2019-02-01, 17:59

I did ask what situation you needed this in and why, and you never answered that question. Please help me understand why this implied behavior is important for your use - I won't consider changing this behavior unless there is a very good reason to do so.
location.reload() doesn't remove the GET arguments
No, it does not -- I never said it did.
"Sometimes, the best way to get what you want is to be a good person." -- Louis Rossmann
"Seek wisdom, not knowledge. Knowledge is of the past; wisdom is of the future." -- Native American proverb
"Linux makes everything difficult." -- Lyceus Anubite

User avatar
adesh
Board Warrior
Board Warrior
Posts: 1277
Joined: 2017-06-06, 07:38

Re: window.location.search="" does nothing

Unread post by adesh » 2019-02-01, 18:28

I think he is trying to implement "Clear all filters" kind of a button for some website. On clicking the button, he wants to load the page with all the query parameters ("search") removed.

dosse91

Re: window.location.search="" does nothing

Unread post by dosse91 » 2019-02-12, 07:24

Sorry for the late reply.
Yes, I'm trying to implement a clear filters option. Am I the only one who does it this way?

User avatar
Moonchild
Pale Moon guru
Pale Moon guru
Posts: 35592
Joined: 2011-08-28, 17:27
Location: Motala, SE
Contact:

Re: window.location.search="" does nothing

Unread post by Moonchild » 2019-02-12, 09:29

dosse91 wrote:Yes, I'm trying to implement a clear filters option. Am I the only one who does it this way?
You're the first asking about this since this behavior was introduced quite a long while back.

It's a low risk change, so see Issue #970 (UXP).
"Sometimes, the best way to get what you want is to be a good person." -- Louis Rossmann
"Seek wisdom, not knowledge. Knowledge is of the past; wisdom is of the future." -- Native American proverb
"Linux makes everything difficult." -- Lyceus Anubite

Locked