Page 1 of 2

Problem with an ampersand in XUL

Posted: 2019-02-28, 21:32
by back0rifize
Hello!

Today I've faced the problem: I created a file, called "about.xul". In this file, I placed a link to my forum's profile. And now, when I try to call this XUL, PM tells me, that I have a syntax error issue.
I'm sure, that an ampersand is the cause of problem, because if I replace it with any other symbol, It seems to be alright.

Re: Problem with an ampersand in XUL

Posted: 2019-02-28, 21:50
by New Tobin Paradigm
In XML the ampersand is a special char.. To use an ampersand literal in an element or attr you can use the entity form:

Code: Select all

&
Though if it is not inside an attr but just enclosed in an element you can also use CDATA but this is easier. XML is always strict in processing the markup so unlike most forms of HTML there isn't any kind of quirks mode in the rendering engine or whatnot.

Re: Problem with an ampersand in XUL

Posted: 2019-03-01, 02:36
by back0rifize
Strange, I thought that the "quotes" must disable any special chars and wrap them into the simple literal symbols :think: ...
And so we have another problem: if "&" change to "&", this link will be broken. I mean, this forum does not parse this link.
Of course, I can code a little script and then all will be alright, but I want to know, why this suppose to be?

Re: Problem with an ampersand in XUL

Posted: 2019-03-01, 09:31
by New Tobin Paradigm
Try using this instead..

Code: Select all

%26

Re: Problem with an ampersand in XUL

Posted: 2019-03-01, 10:05
by back0rifize
Believe me, I've already tried this too with no result ;) . Thank you.

Re: Problem with an ampersand in XUL

Posted: 2019-03-01, 10:56
by JustOff
back0rifize wrote:And so we have another problem: if "&" change to "&", this link will be broken.
No, it will not.

Re: Problem with an ampersand in XUL

Posted: 2019-03-01, 12:50
by New Tobin Paradigm
JustOff it depends on the browser and server software. I have ran into this my self.. However, the %26 SHOULD work...

Well maybe you should just assign the attr using js instead.

Re: Problem with an ampersand in XUL

Posted: 2019-03-01, 13:27
by JustOff
Maybe in some cases something might go wrong, but I checked that in the about.xul file in the Calendate extension in question, & works as expected.

Re: Problem with an ampersand in XUL

Posted: 2019-03-01, 13:43
by Moonchild
This forum blocks URLs with "&" as a literal string in the URL to mitigate bot abuse - most websites do not.

Re: Problem with an ampersand in XUL

Posted: 2019-03-01, 14:09
by JustOff
There will be no "&" in the forum URL, because when it's used in the "href" attribute of the "label" element in the "about.xul", it becomes "&" when the link is opened.

Re: Problem with an ampersand in XUL

Posted: 2019-03-02, 00:36
by back0rifize
Moonchild wrote:This forum blocks URLs with "&" as a literal string in the URL to mitigate bot abuse - most websites do not.
Other words, I was right that neither "&" nor "%26" will not work? In my case this is right what exactly happened.
JustOff wrote:There will be no "&" in the forum URL, because when it's used in the "href" attribute of the "label" element in the "about.xul", it becomes "&" when the link is opened.
With all my respect, but it's not working. Maybe I'm dumb?

One way or the other, I've done an update yesterday, and simply remove this profile link completely. I didn't include a JS-file in "About XUL", because the only reason, why I have no desire in doing it - is include yet another JS only for solving such kind of a situation. It's better to abandon an idea, than to use a complex way to solve a simple problem.
Think, this topic may be closed. Thanks to all for your answers!

Re: Problem with an ampersand in XUL

Posted: 2019-03-02, 01:29
by New Tobin Paradigm
You can add javascript directly to XUL and if you CDATA the contents of the script tag you can add that one onload function to add the attr. It just isn't best practice to do js in xul files in-line but know what.. I don't have a problem for a one off workaround..

Re: Problem with an ampersand in XUL

Posted: 2019-03-02, 03:18
by back0rifize
Yeah, I know about CDATA, and I've already used it in previous versions (below 3.0, Firefox only). Since I've ported my add-on to PM, I use a links to a JS-files with a window.addEventListener(); instead for more clearance.

Re: Problem with an ampersand in XUL

Posted: 2019-03-02, 08:07
by Moonchild
back0rifize wrote:Other words, I was right that neither "&" nor "%26" will not work? In my case this is right what exactly happened.
No, you're not right. I'm only saying that if your code does a request to the forum server with "&" as a literal string in the URL, it will be refused. I didn't say anything about %26, nor did I say anything about how it's specifically handled in your situation or what is sent to the server -- just providing information that might save you some troubleshooting IF you're sending "&" in your URLs for some reason!

Re: Problem with an ampersand in XUL

Posted: 2019-03-02, 08:25
by JustOff
back0rifize wrote:With all my respect, but it's not working.
Please check your PM.

Re: Problem with an ampersand in XUL

Posted: 2019-03-02, 11:40
by back0rifize
JustOff wrote:Please check your PM.
Problem solved, thank you, JustOff!

Re: Problem with an ampersand in XUL

Posted: 2019-03-02, 15:40
by New Tobin Paradigm
Mind sharing this solution?

Re: Problem with an ampersand in XUL

Posted: 2019-03-02, 16:47
by JustOff
Tobin, your initial advice to use "&" was absolutely correct, I just applied it to the back0rifize's extension and sent him the result. I guess he simply made a typo somewhere when previously reported a failure.

Re: Problem with an ampersand in XUL

Posted: 2019-03-02, 17:05
by New Tobin Paradigm
No, that isn't smoke, it's steam. Steam from the steamed clams we're having. Mmmm, steamed clams!

Re: Problem with an ampersand in XUL

Posted: 2019-03-02, 17:37
by JustOff
Yep. The Aurora Borealis. At this time of year. At this time of day. In this part of the country. Localized entirely within your kitchen.