为什么浏览器在URL具有多个查询字符串参数时禁止获取XSLT样式表

huangapple go评论77阅读模式
英文:

Why do browsers disallow fetch of XSLT stylesheet when URL has multiple query string parameters

问题

我有一个XML资源,其中在处理指令中引用了一个XSLT样式表,该处理指令具有一个href属性。该属性的URL可以有一个查询字符串参数,也可以没有。然而,当URL具有多个查询字符串参数时,浏览器似乎甚至不会获取样式表。为什么会发生这种情况?

这是我的意思。首先,我有XML/XSLT文件,改编自w3schools示例,保存在本地磁盘上,命名为scratch.xmlstyle.xml。我编辑了XML文件,在顶部附近添加了这个处理指令(第二行):

<?xml-stylesheet href="style.xsl" type="text/xsl"?>

我在此目录中运行一个Web服务器,使用以下命令:

python3 -m http.server

如果我在浏览器中获取位于http://localhost:8000/scratch.xml的XML文件,它会获取样式表并正常渲染。如果我更改href属性并添加一个查询字符串参数,使其看起来像这样:

<?xml-stylesheet href="style.xsl?foo=1" type="text/xsl"?>

它会获取样式表并正常渲染。然而,如果我更改href属性并添加一个以上的参数,使其看起来像这样:

<?xml-stylesheet href="style.xsl?foo=1&bar=2" type="text/xsl"?>

浏览器甚至停止尝试获取样式表。这在Chrome和Firefox中都发生。我通过嗅探流量来验证它甚至没有请求样式表:

ngrep -d lo port 8000

说实话,我觉得这令人困惑。

我至少尝试过两种不同的浏览器,以及至少两种不同的Web服务器(nginx和Python服务器)。我没有预期样式表URL的形式会有任何影响。

英文:

I have an XML resource that references an XSLT stylesheet in a processing instruction, which has an href attribute. The URL for that attribute can have one query string parameter or none. However, when the URL has more than one query string parameter the browser seems not even to fetch the stylesheet. Why does this happen?

Here's what I mean. First, I have XML/XSLT files adapted from this w3schools example, saved to local disk as scratch.xml and style.xml. I edited the XML file to add this processing instruction near the top (second line):

&lt;?xml-stylesheet href=&quot;style.xsl&quot; type=&quot;text/xsl&quot;?&gt;

I'm running a web server in this directory using:

python3 -m http.server

If I get the XML file in the browser at http://localhost:8000/scratch.xml it fetches the stylesheet and renders fine. If I change the href attribute and add one query string parameter so that it looks like this:

&lt;?xml-stylesheet href=&quot;style.xsl?foo=1&quot; type=&quot;text/xsl&quot;?&gt;

it fetches the stylesheet and renders fine. However, if I change the href attribute and add one more parameter so that it looks like this:

&lt;?xml-stylesheet href=&quot;style.xsl?foo=1&amp;bar=2&quot; type=&quot;text/xsl&quot;?&gt;

the browser stops even trying to fetch the stylsheet. This occurs both in Chrome and in Firefox. I verified that it's not even requesting the stylesheet by sniffing the traffic:

ngrep -d lo port 8000

I find this baffling, honestly.

I've tried at least two different browsers, and I've tried at least two different web servers (nginx and the python server). I didn't expect the form of the stylesheet URL to have an bearing at all.

答案1

得分: 4

Your XML is not well-formed because the &amp; character needs to be escaped as &amp;amp;.

英文:

Your XML is not well-formed because the &amp; character needs to be escaped as &amp;amp;.

huangapple
  • 本文由 发表于 2023年3月12日 07:57:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/75710300.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定