Leerzeichen in URL bei XHTML – SELFHTML-Forum Forum als Ergänzung zum SELFHTML-Wiki und zur Dokumentation SELFHTML https://forum.selfhtml.org/self?srt=yes Leerzeichen in URL bei XHTML Tue, 13 Apr 21 17:23:59 Z https://forum.selfhtml.org/self/2021/apr/13/leerzeichen-in-url-bei-xhtml/1787248?srt=yes#m1787248 https://forum.selfhtml.org/self/2021/apr/13/leerzeichen-in-url-bei-xhtml/1787248?srt=yes#m1787248 <p>Hallo,</p> <p>mir sind die Probleme bewusst, sofern Leerzeichen nicht prozent-enkodiert bei URL-Angaben erfolgen. Allerdings habe ich eine allgemeine Verständnisfrage bei der Verwendung von URLs und der Valdierung, z.B. bei Hyperlinks mit Attribute href</p> <p>Mein grundsätzliches Verständnis war wie folgt:</p> <p>Quellcode: <a href=" http://www.leer zeichen.org">Page</a> --> XML-Processor --> Lexical space: <a href="http://www.leer%20zeichen.org">Page</a> --> XML Validierung</p> <p>Mein Verständnis basiert auf der Überlegung, dass XML attribute zuerst "normalisiert" werden durch den XML-Prozessor. Und danach erfolgt die Validierung.</p> <p>Deshalb meine Frage, wäre der oben aufgeführte Quellcode XHTML valide (gibt es Unterschiede zwischen XHTML1.1 und (X)HTML5 hierbei? Ist mein Verständnis korrekt, dass der lexical space der obigen Darstellung entspricht, d.h. leading und trailing whitespaces entfernt und alle anderen whitespaces normalized?</p> <p>Gruss</p> Leerzeichen in URL bei XHTML Tue, 13 Apr 21 17:58:30 Z https://forum.selfhtml.org/self/2021/apr/13/leerzeichen-in-url-bei-xhtml/1787249?srt=yes#m1787249 https://forum.selfhtml.org/self/2021/apr/13/leerzeichen-in-url-bei-xhtml/1787249?srt=yes#m1787249 <p>Hallo Michael,</p> <blockquote> <p>Quellcode: <a href=" http://www.leer zeichen.org">Page</a><br> --> XML-Processor<br> --> Lexical space: <a href="http://www.leer%20zeichen.org">Page</a><br> --> XML Validierung</p> </blockquote> <p>ich bin a) selbst nicht ganz sattelfest bei der Frage und b) nicht sicher, dass ich dein Anliegen überhaupt richtig verstehe. Ich vermute aber, dass du auf dem Holzweg bist. Lassen wir das Entfernen von führendem Whitespace mal außen vor - ein XML-Parser wird aber sicher keine Ersetzung von Blanks zu %20 vornehmen.</p> <blockquote> <p>Mein Verständnis basiert auf der Überlegung, dass XML attribute zuerst "normalisiert" werden durch den XML-Prozessor. Und danach erfolgt die Validierung.</p> </blockquote> <p>Definiere "normalisiert". Weder in XML, noch in HTML unterliegen Attribut<strong>werte</strong> irgendwelchen Syntaxregeln - außer dass Sonderzeichen maskiert werden müssen. Die korrekte Maskierung ist aber hier z.B. &lt; oder &quot;, die Prozent-Codierung ist eine ganz andere Baustelle. Zudem gelten Blanks <em>innerhalb</em> von Attributwerten nicht als Sonderzeichen, die maskiert werden müssten.</p> <blockquote> <p>Deshalb meine Frage, wäre der oben aufgeführte Quellcode XHTML valide (gibt es Unterschiede zwischen XHTML1.1 und (X)HTML5 hierbei?</p> </blockquote> <p>Ja, er wäre auch in jedem HTML-Dialekt valide. Die Syntaxregeln von HTML und XML gelten nicht in Attributwerten. Die sind sozusagen Freiwild.</p> <blockquote> <p>Ist mein Verständnis korrekt, dass der lexical space der obigen Darstellung entspricht, d.h. leading und trailing whitespaces entfernt und alle anderen whitespaces normalized?</p> </blockquote> <p>Nein, in Attributwerten findet auch keine Whitespace-Normalisierung statt (du denkst an die Reduktion von mehreren Blanks zu einem einzigen, nehme ich an).</p> <p>Was du hier ansprichst, ist eine ganz andere Baustelle. Nämlich die kontextgerechte Maskierung eines Attributwerts in dem Moment, wo er als URL interpretiert wird. Das passiert aber nicht bei der Validierung von XML oder HTML, sondern erst beim Generieren des HTML-DOM.</p> <p>Live long and <s>pros</s> healthy,<br>  Martin</p> <div class="signature">-- <br> Wer respektiert werden will, sollte zunächst damit anfangen, andere zu respektieren. </div> Leerzeichen in URL bei XHTML Wed, 14 Apr 21 09:24:26 Z https://forum.selfhtml.org/self/2021/apr/13/leerzeichen-in-url-bei-xhtml/1787270?srt=yes#m1787270 https://forum.selfhtml.org/self/2021/apr/13/leerzeichen-in-url-bei-xhtml/1787270?srt=yes#m1787270 <p>Moin Michael,</p> <blockquote> <p>mir sind die Probleme bewusst, sofern Leerzeichen nicht prozent-enkodiert bei URL-Angaben erfolgen. Allerdings habe ich eine allgemeine Verständnisfrage bei der Verwendung von URLs und der Valdierung, z.B. bei Hyperlinks mit Attribute href</p> <p>Mein grundsätzliches Verständnis war wie folgt:</p> <p>Quellcode: <code class="language-xml"><span class="token tag"><span class="token tag"><span class="token punctuation"><</span>a</span> <span class="token attr-name">href</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span> http://www.leer zeichen.org<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>Page<span class="token tag"><span class="token tag"><span class="token punctuation"></</span>a</span><span class="token punctuation">></span></span></code> --> XML-Processor --> Lexical space: <code class="language-xml"><span class="token tag"><span class="token tag"><span class="token punctuation"><</span>a</span> <span class="token attr-name">href</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>http://www.leer%20zeichen.org<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>Page<span class="token tag"><span class="token tag"><span class="token punctuation"></</span>a</span><span class="token punctuation">></span></span></code> --> XML Validierung</p> </blockquote> <p>Dafür müsste der XML-Prozessor wissen, dass der Inhalt des Attributs <code>href</code> ein URI ist und entsprechend kodieren. Zumindest das <code>%20</code> stelle ich mal in Frage, weil ich das noch nirgends so erlebt habe.</p> <blockquote> <p>Deshalb meine Frage, wäre der oben aufgeführte Quellcode XHTML valide (gibt es Unterschiede zwischen XHTML1.1 und (X)HTML5 hierbei? Ist mein Verständnis korrekt, dass der lexical space der obigen Darstellung entspricht, d.h. leading und trailing whitespaces entfernt und alle anderen whitespaces normalized?</p> </blockquote> <p>Was sagt denn <a href="https://validator.w3.org/" rel="nofollow noopener noreferrer">https://validator.w3.org/</a>?</p> <p>Viele Grüße<br> Robert</p> Leerzeichen in URL bei XHTML Wed, 14 Apr 21 06:56:31 Z https://forum.selfhtml.org/self/2021/apr/13/leerzeichen-in-url-bei-xhtml/1787255?srt=yes#m1787255 https://forum.selfhtml.org/self/2021/apr/13/leerzeichen-in-url-bei-xhtml/1787255?srt=yes#m1787255 <p>Hallo Martin,</p> <p>vielen dank für die Information. Aber eine Frage bleibt trotzdem noch</p> <blockquote> <blockquote> <p>Ist mein Verständnis korrekt, dass der lexical space der obigen Darstellung entspricht, d.h. leading und trailing whitespaces entfernt und alle anderen whitespaces normalized?</p> </blockquote> <p>Nein, in Attributwerten findet auch keine Whitespace-Normalisierung statt (du denkst an die Reduktion von mehreren Blanks zu einem einzigen, nehme ich an).</p> </blockquote> <p>Verstehe ich es richtig, dass bei XHTML keine Attribute Normalization vorgenommen wird, so wie für XML beschrieben?</p> <p><a href="https://www.w3.org/TR/xml/#AVNormalize" rel="nofollow noopener noreferrer">https://www.w3.org/TR/xml/#AVNormalize</a></p> <p>3.3.3 Attribute-Value Normalization</p> <p>Before the value of an attribute is passed to the application or checked for validity, the XML processor MUST normalize the attribute value by applying the algorithm below, or by using some other method such that the value passed to the application is the same as that produced by the algorithm.</p> <pre><code>All line breaks MUST have been normalized on input to #xA as described in 2.11 End-of-Line Handling, so the rest of this algorithm operates on text normalized in this way. Begin with a normalized value consisting of the empty string. For each character, entity reference, or character reference in the unnormalized attribute value, beginning with the first and continuing to the last, do the following: For a character reference, append the referenced character to the normalized value. For an entity reference, recursively apply step 3 of this algorithm to the replacement text of the entity. For a white space character (#x20, #xD, #xA, #x9), append a space character (#x20) to the normalized value. For another character, append the character to the normalized value. </code></pre> <p>If the attribute type is not CDATA, then the XML processor MUST further process the normalized attribute value by discarding any leading and trailing space (#x20) characters, and by replacing sequences of space (#x20) characters by a single space (#x20) character.</p> <p>Note that if the unnormalized attribute value contains a character reference to a white space character other than space (#x20), the normalized value contains the referenced character itself (#xD, #xA or #x9). This contrasts with the case where the unnormalized value contains a white space character (not a reference), which is replaced with a space character (#x20) in the normalized value and also contrasts with the case where the unnormalized value contains an entity reference whose replacement text contains a white space character; being recursively processed, the white space character is replaced with a space character (#x20) in the normalized value.</p> <p>All attributes for which no declaration has been read SHOULD be treated by a non-validating processor as if declared CDATA.</p> <p>It is an error if an attribute value contains a reference to an entity for which no declaration has been read.</p> Leerzeichen in URL bei XHTML Wed, 14 Apr 21 07:30:07 Z https://forum.selfhtml.org/self/2021/apr/13/leerzeichen-in-url-bei-xhtml/1787258?srt=yes#m1787258 https://forum.selfhtml.org/self/2021/apr/13/leerzeichen-in-url-bei-xhtml/1787258?srt=yes#m1787258 <p>Hallo,</p> <blockquote> <blockquote> <blockquote> <p>Ist mein Verständnis korrekt, dass der lexical space der obigen Darstellung entspricht, d.h. leading und trailing whitespaces entfernt und alle anderen whitespaces normalized?</p> </blockquote> <p>Nein, in Attributwerten findet auch keine Whitespace-Normalisierung statt (du denkst an die Reduktion von mehreren Blanks zu einem einzigen, nehme ich an).</p> </blockquote> <p>Verstehe ich es richtig, dass bei XHTML keine Attribute Normalization vorgenommen wird, so wie für XML beschrieben?</p> </blockquote> <p>Was du da als Attribute Normalization zitierst, kannte ich noch gar nicht. Ich dachte tatsächlich nur daran, dass mehrere Whitespace-Zeichen zu <em>einem</em> zusammengefasst werden. Aber genau das gilt üblicherweise nicht in Attributwerten.<br> Deshalb mein "Nein".</p> <blockquote> <p><a href="https://www.w3.org/TR/xml/#AVNormalize" rel="nofollow noopener noreferrer">https://www.w3.org/TR/xml/#AVNormalize</a></p> <p>3.3.3 Attribute-Value Normalization</p> <p>Before the value of an attribute is passed to the application or checked for validity, the XML processor MUST normalize the attribute value by applying the algorithm below, or by using some other method such that the value passed to the application is the same as that produced by the algorithm.</p> </blockquote> <p>Was da beschrieben wird, ist vor allem die Auflösung von Entity-Referenzen und NCR (das war klar), und der Ersatz <strong>aller</strong> Whitespace-Zeichen durch 0x20 (das wusste ich nicht).</p> <blockquote> <p>If the attribute type is not CDATA, then the XML processor MUST further process the normalized attribute value by discarding any leading and trailing space (#x20) characters, and by replacing sequences of space (#x20) characters by a single space (#x20) character.</p> </blockquote> <p>Aha. Das finde ich interessant - es gibt also auch bei Attributen die Unterscheidung zwischen CDATA und PCDATA. Ich dachte bisher, die gäbe es nur für den Elementinhalt. Allerdings steht da auch noch, dass CDATA der Regelfall ist, so dass die Kompression von Whitespace üblicherweise nicht stattfindet.</p> <p>Aber um auf die Ausgangsfrage zurückzukommen: Ein validierender XML- oder XHTML-Parser wird ein Leerzeichen in einem Attributwert sicher nicht in %20 umwandeln. Er stört sich aber auch nicht daran, denn Leerzeichen in Attributwerten sind vollkommen valide.</p> <p>Erst wenn der Browser das DOM aufbaut und den Attributwert als URL identifiziert hat, muss er Leerzeichen darin in %20 umwandlen, weil sonst ein ungültiger HTTP-Request beim Anfordern der referenzierten Ressource entstünde.</p> <p>Live long and <s>pros</s> healthy,<br>  Martin</p> <div class="signature">-- <br> Wer respektiert werden will, sollte zunächst damit anfangen, andere zu respektieren. </div> Leerzeichen in URL bei XHTML Wed, 14 Apr 21 08:32:55 Z https://forum.selfhtml.org/self/2021/apr/13/leerzeichen-in-url-bei-xhtml/1787263?srt=yes#m1787263 https://forum.selfhtml.org/self/2021/apr/13/leerzeichen-in-url-bei-xhtml/1787263?srt=yes#m1787263 <blockquote> <p>Aber um auf die Ausgangsfrage zurückzukommen: Ein validierender XML- oder XHTML-Parser wird ein Leerzeichen in einem Attributwert sicher nicht in %20 umwandeln. Er stört sich aber auch nicht daran, denn Leerzeichen in Attributwerten sind vollkommen valide.</p> </blockquote> <p>Aber gerade das steht doch gleich im ersten Satz: "Before the value of an attribute is passed to the application <strong>or checked for validity</strong>, the XML processor MUST normalize the attribute value by applying the algorithm below"</p> <p>Und deshalb war mein Verständnis, dass im lexical space die Leerzeichen immer percent-encoded vorliegen (zumindest bei XHTML). Und normalized in Abhängigkeit von CDATA.</p> Leerzeichen in URL bei XHTML Wed, 14 Apr 21 09:12:37 Z https://forum.selfhtml.org/self/2021/apr/13/leerzeichen-in-url-bei-xhtml/1787268?srt=yes#m1787268 https://forum.selfhtml.org/self/2021/apr/13/leerzeichen-in-url-bei-xhtml/1787268?srt=yes#m1787268 <p>Hallo Michael,</p> <blockquote> <p>Aber gerade das steht doch gleich im ersten Satz: "Before the value of an attribute is passed to the application <strong>or checked for validity</strong>, the XML processor MUST normalize the attribute value by applying the algorithm below"</p> <p>Und deshalb war mein Verständnis, dass im lexical space die Leerzeichen immer percent-encoded vorliegen (zumindest bei XHTML). Und normalized in Abhängigkeit von CDATA.</p> </blockquote> <p>Die „Prozent-Kodierung“ wird allerdings im URI-Kontext verwendet und nicht im X(HT)ML-Kontext. Bei X(HT)ML wäre es <code class="language-xml"><span class="token entity" title="&#x20;">&#x20;</span></code> – wenn das Leerzeichen nicht auch als solches schon verwendet würde.</p> <p>Viele Grüße<br> Robert</p>