Extra, somewhat excessive resolve-uri test
authorabraaksm
Wed, 08 Apr 2015 03:01:03 +0200
changeset 940 bde9163d9548
parent 939 f0c29b5d9a9b
child 941 2ced139465ff
Extra, somewhat excessive resolve-uri test
tests/fn/resolve-uri/_resolve-uri-test-set.xml
tests/fn/resolve-uri/resolve-uri-022.out
tests/fn/resolve-uri/resolve-uri-022.xsl
--- a/tests/fn/resolve-uri/_resolve-uri-test-set.xml	Wed Apr 08 01:32:09 2015 +0200
+++ b/tests/fn/resolve-uri/_resolve-uri-test-set.xml	Wed Apr 08 03:01:03 2015 +0200
@@ -347,4 +347,24 @@
          <assert-xml><![CDATA[<out><e>resolve-uri/level1/element.xml</e><p>resolve-uri/level1/pi.xml</p></out>]]></assert-xml>
       </result>
    </test-case>
+   
+   <test-case name="resolve-uri-022">
+      <description>
+         Tests deep dotted paths and paths that try to get past the root, checks the mandatory RFC rules about removing the dots
+         Note that from a recent discussion it is understood that 
+          - if an xml:base contains dotted paths, these are returned unchanged (no dot-replacement)
+          - if resolve-uri has $relative absolute path, it is returned unchanged (no dot-replacement)
+          - if resolve-uri has empty string for $relative, then $absolute is returned unchanged (no dot-replacement)         
+      </description>
+      <created by="Abel Braaksma" on="2015-03-30"/>
+      <dependencies>
+         <spec value="XSLT20+"/>
+      </dependencies>
+      <test>
+         <stylesheet file="resolve-uri-022.xsl"/>
+      </test>
+      <result>
+         <assert-xml file="resolve-uri-022.out"/>
+      </result>
+   </test-case>
 </test-set>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/fn/resolve-uri/resolve-uri-022.out	Wed Apr 08 03:01:03 2015 +0200
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<out xmlns:xs="http://www.w3.org/2001/XMLSchema"
+     xml:base="http://example.com/a/b/c/d/../d/e/f/g/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z">
+   <base>http://example.com/a/b/c/d/e/f/g/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/Z</base>
+   <base>http://example.com/a/b/c/d/../d/e/f/g/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z</base>
+   <base>http://example.com/a/b/c/d/../d/e/f/g/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z</base>
+   <resolve>http://example.com/a/b/c/d/e/f/g/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/</resolve>
+   <resolve>http://example.com/a/b/c/d/e/f/g/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/</resolve>
+   <resolve>http://example.com/a/b/c/d/e/f/g/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/</resolve>
+   <resolve>http://example.com/</resolve>
+   <resolve>http://example.com/</resolve>
+   <resolve>http://example.com/</resolve>
+   <resolve>http://example.com/</resolve>
+   <resolve>http://example.com/</resolve>
+   <resolve>http://example.com/</resolve>
+   <resolve>http://example.com/</resolve>
+   <resolve>http://example.com/</resolve>
+   <resolve>http://example.com/a/b/c/d/e/f/g/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/</resolve>
+   <resolve>http://example.com/a/b/c/d/e/f/g/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/</resolve>
+   <resolve>http://example.com/a/b/c/d/e/f/g/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/</resolve>
+   <resolve>http://example.com/a/b/c/d/e/f/g/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/</resolve>
+   <resolve>http://example.com/a/b/c/d/e/f/g/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/</resolve>
+   <resolve>http://example.com/a/b/c/d/e/f/g/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/</resolve>
+   <resolve>http://example.com/a/b/c/d/e/f/g/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/</resolve>
+   <resolve>http://example.com/a/b/c/d/e/f/g/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/</resolve>
+   <resolve>http://example.com/a/b/c/d/e/f/g/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/</resolve>
+   <resolve>http://example.com/a/b/c/d/e/f/g/i/j/k/l/m/n/o/p/q/r/s/t/u/v/</resolve>
+   <resolve>http://example.com/a/b/c/d/e/f/g/i/j/k/l/m/n/o/p/q/r/s/t/u/</resolve>
+   <resolve>http://example.com/a/b/c/d/e/f/g/i/j/k/l/m/n/o/p/q/r/s/t/</resolve>
+   <resolve>http://example.com/a/b/c/d/e/f/g/i/j/k/l/m/n/o/p/q/r/s/</resolve>
+   <resolve>http://example.com/a/b/c/d/e/f/g/i/j/k/l/m/n/o/p/q/r/</resolve>
+   <resolve>http://example.com/a/b/c/d/e/f/g/i/j/k/l/m/n/o/p/q/</resolve>
+   <resolve>http://example.com/a/b/c/d/e/f/g/i/j/k/l/m/n/o/p/</resolve>
+   <resolve>http://example.com/a/b/c/d/e/f/g/i/j/k/l/m/n/o/</resolve>
+   <resolve>http://example.com/a/b/c/d/e/f/g/i/j/k/l/m/n/</resolve>
+   <resolve>http://example.com/a/b/c/d/e/f/g/i/j/k/l/m/</resolve>
+   <resolve>http://example.com/a/b/c/d/e/f/g/i/j/k/l/</resolve>
+   <resolve>http://example.com/a/b/c/d/e/f/g/i/j/k/</resolve>
+   <resolve>http://example.com/a/b/c/d/e/f/g/i/j/</resolve>
+   <resolve>http://example.com/a/b/c/d/e/f/g/i/</resolve>
+   <resolve>http://example.com/a/b/c/d/e/f/g/</resolve>
+   <resolve>http://example.com/a/b/c/d/e/f/</resolve>
+   <resolve>http://example.com/a/b/c/d/e/</resolve>
+   <resolve>http://example.com/a/b/c/d/</resolve>
+   <resolve>http://example.com/a/b/c/</resolve>
+   <resolve>http://example.com/a/b/</resolve>
+   <resolve>http://example.com/a/</resolve>
+   <resolve>http://example.com/a/</resolve>
+   <resolve>http://example.com/</resolve>
+   <resolve>http://example.com/</resolve>
+   <resolve>http://example.com/</resolve>
+   <resolve>http://example.com/</resolve>
+</out>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/fn/resolve-uri/resolve-uri-022.xsl	Wed Apr 08 03:01:03 2015 +0200
@@ -0,0 +1,97 @@
+<?xml version="1.0"?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+    xmlns:xs="http://www.w3.org/2001/XMLSchema"
+    version="3.0" expand-text="yes">
+
+    <!-- 
+        Rudimentary but excessive test for deeper dotted relative paths with resolve-uri and base uris
+        Test covers:
+        - dot elements in relative base uri
+        - dot elements in rel uri
+        - dot elements that try to get past the auth segment (should return scheme '://' auth '/')
+        - absolute path in base uri that, because it must be resolved, acc to RFC 3986, should remove dot segments, quote:
+        - none of these tests have $relative ending with a non-dotted segment, which means that all resolution will end with trailing "/"
+        
+        "However, some deployed implementations incorrectly assume that reference resolution
+        is not necessary when the reference is already a URI and thus fail to remove 
+        dot-segments when they occur in non-relative paths.  URI normalizers should remove 
+        dot-segments by applying the remove_dot_segments algorithm to the path, as described 
+        in Section 5.2.4."
+    -->
+    
+
+    <xsl:output indent="yes"></xsl:output>
+
+    <xsl:template match="/" name="xsl:initial-template">
+        
+        <out xml:base="http://example.com/a/b/c/d/../d/e/f/g/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z">
+            <xsl:variable name="base" select="static-base-uri()" xml:base="Z/../Z"/>
+            
+            <!-- varying bases -->
+            <base>{$base}</base>
+            <base>{static-base-uri()}</base>
+            <base>{resolve-uri(static-base-uri(), static-base-uri())}</base>
+            
+            <!-- ignorable dots, *but* removes the "z", leaves the trailing "/" -->
+            <resolve>{resolve-uri('.')}</resolve>
+            <resolve>{resolve-uri('./')}</resolve>
+            <resolve>{resolve-uri('./././././././')}</resolve>
+            
+            <!-- variants of trying to get past the root, should return root path acc. to RFC, and *must* include root path leading "/" -->
+            <resolve>{resolve-uri('/')}</resolve>
+            <resolve>{resolve-uri('/./././././././')}</resolve>
+            <resolve>{resolve-uri('/../../.././././././././')}</resolve>
+            <resolve>{resolve-uri('/..')}</resolve>
+            <resolve>{resolve-uri('/../')}</resolve>
+            <resolve>{resolve-uri('../', 'http://example.com')}</resolve>
+            <resolve>{resolve-uri('../Z/..', 'http://example.com')}</resolve>
+            <resolve>{resolve-uri('./.', 'http://example.com')}</resolve>
+            
+            <!-- variants of one level up, ends with "/x/" -->
+            <resolve>{resolve-uri('..')}</resolve>
+            <resolve>{resolve-uri('../')}</resolve>
+            <resolve>{resolve-uri('../.')}</resolve>
+            <resolve>{resolve-uri('.././')}</resolve>
+            <resolve>{resolve-uri('.././')}</resolve>
+            <resolve>{resolve-uri('./././.././.')}</resolve>
+            
+            <!-- tests overlap of dotted path, where multiple dots on the right of a non-dotted segment could (with a wrong algo) potentially remove dotted elements further to the left -->
+            <resolve>{resolve-uri('./X/Y/Z/../W/../../.././..')}</resolve>
+            <resolve>{resolve-uri('../../.././X/Y/Z/../W/../../.././../v/w/x/')}</resolve>
+            
+            <!-- each following line ends with a lower letter in the alphabet, starting with "/w/" -->
+            <resolve>{resolve-uri('../../')}</resolve>
+            <resolve>{resolve-uri('../../../')}</resolve>
+            <resolve>{resolve-uri('../../../../')}</resolve>
+            <resolve>{resolve-uri('../../../../../')}</resolve>
+            <resolve>{resolve-uri('../../../../../../')}</resolve>
+            <resolve>{resolve-uri('../../../../../../../')}</resolve>
+            <resolve>{resolve-uri('../../../../../../../../')}</resolve>
+            <resolve>{resolve-uri('../../../../../../../../../')}</resolve>
+            <resolve>{resolve-uri('../../../../../../../../../../')}</resolve>
+            <resolve>{resolve-uri('../../../../../../../../../../../')}</resolve>
+            <resolve>{resolve-uri('../../../../../../../../../../../../')}</resolve>
+            <resolve>{resolve-uri('../../../../../../../../../../../../../')}</resolve>
+            <resolve>{resolve-uri('../../../../../../../../../../../../../../')}</resolve>
+            <resolve>{resolve-uri('../../../../../../../../../../../../../../../')}</resolve>
+            <resolve>{resolve-uri('../../../../../../../../../../../../../../../../')}</resolve>
+            <resolve>{resolve-uri('../../../../../../../../../../../../../../../../../')}</resolve>
+            <resolve>{resolve-uri('../../../../../../../../../../../../../../../../../../')}</resolve>
+            <resolve>{resolve-uri('../../../../../../../../../../../../../../../../../../../')}</resolve>
+            <resolve>{resolve-uri('../../../../../../../../../../../../../../../../../../../../')}</resolve>
+            <resolve>{resolve-uri('../../../../../../../../../../../../../../../../../../../../../')}</resolve>
+            <resolve>{resolve-uri('../../../../../../../../../../../../../../../../../../../../../../')}</resolve>
+            <resolve>{resolve-uri('../../../../../../../../../../../../../../../../../../../../../../../')}</resolve>
+            
+            <!-- variants that should end with "/a/" -->
+            <resolve>{resolve-uri('./././../../../../../../../../../././././../../../../../../../../../../../../../../././.')}</resolve>
+            
+            <!-- variants that try to get past the root, should return root with dotted parts removed -->
+            <resolve>{resolve-uri('../../../../../../../../../../../../../../../../../../../../../../../../')}</resolve>
+            <resolve>{resolve-uri('../../../../../../../../../../../../../../../../../../../../../../../../../')}</resolve>
+            <resolve>{resolve-uri('../../../../../../../../../../../../../../../../../../../../../../../../../../')}</resolve>
+            <resolve>{resolve-uri('/../../../../../../../../../../../../../../../../../../../../../../../')}</resolve>
+        </out>
+    </xsl:template>
+
+</xsl:stylesheet>