1515import static org .junit .jupiter .api .Assertions .assertFalse ;
1616import static org .junit .jupiter .api .Assertions .assertNotNull ;
1717import static org .junit .jupiter .api .Assertions .assertNull ;
18+ import static org .junit .jupiter .api .Assertions .assertThrows ;
1819import static org .junit .jupiter .api .Assertions .assertTrue ;
1920
2021import java .io .IOException ;
5657import io .sf .carte .doc .style .css .om .CSSOMParser ;
5758import io .sf .carte .doc .style .css .om .CSSRuleArrayList ;
5859import io .sf .carte .doc .style .css .om .ComputedCSSStyle ;
59- import io .sf .carte .doc .style .css .om .DOMCSSStyleSheetFactoryTest ;
6060import io .sf .carte .doc .style .css .om .MediaRule ;
6161import io .sf .carte .doc .style .css .om .PropertyCountVisitor ;
62+ import io .sf .carte .doc .style .css .om .SampleCSS ;
6263import io .sf .carte .doc .style .css .om .StyleCountVisitor ;
6364import io .sf .carte .doc .style .css .om .StyleRule ;
6465import io .sf .carte .doc .style .css .om .StyleSheetList ;
@@ -72,7 +73,7 @@ public class XHTMLDocumentTest {
7273
7374 @ BeforeEach
7475 public void setUp () throws Exception {
75- Reader re = DOMCSSStyleSheetFactoryTest .sampleHTMLReader ();
76+ Reader re = SampleCSS .sampleHTMLReader ();
7677 org .xml .sax .InputSource isrc = new org .xml .sax .InputSource (re );
7778 xhtmlDoc = TestUtil .parseXML (isrc );
7879 re .close ();
@@ -489,7 +490,7 @@ public void testComputedStyleAttr() {
489490 /*
490491 * attr() value, string expected type, do not reparse.
491492 */
492- elm .getOverrideStyle (null ).setCssText ("margin-left:attr(leftmargin string)" );
493+ elm .getOverrideStyle (null ).setCssText ("margin-left:attr(leftmargin raw- string)" );
493494 style = elm .getComputedStyle (null );
494495 marginLeft = (CSSTypedValue ) style .getPropertyCSSValue ("margin-left" );
495496 assertEquals (CSSValue .Type .STRING , marginLeft .getPrimitiveType ());
@@ -954,7 +955,7 @@ public void testCompatComputedStyle() {
954955
955956 @ Test
956957 public void testCascade () throws IOException {
957- Reader re = DOMCSSStyleSheetFactoryTest .loadSampleUserCSSReader ();
958+ Reader re = SampleCSS .loadSampleUserCSSReader ();
958959 xhtmlDoc .getDocumentFactory ().getStyleSheetFactory ().setUserStyleSheet (re );
959960 re .close ();
960961 CSSElement elm = xhtmlDoc .getElementById ("para1" );
@@ -1088,6 +1089,32 @@ public void testBaseElement() throws MalformedURLException {
10881089 CSSElement base = (CSSElement ) xhtmlDoc .getElementsByTagName ("base" ).item (0 );
10891090 base .setAttribute ("href" , "http://www.example.com/newbase/" );
10901091 assertEquals ("http://www.example.com/newbase/" , xhtmlDoc .getBaseURI ());
1092+
1093+ // Check that getURL works
1094+ assertEquals ("http://www.example.com/newbase/b?e=f&g=h" ,
1095+ xhtmlDoc .getURL ("b?e=f&g=h" ).toExternalForm ());
1096+
1097+ assertEquals (
1098+ "https://fonts.googleapis.com/css2?family=Playfair+Display:ital,wght@0,400..900;1,400..900&family=Raleway:wght@200&display=swap" ,
1099+ xhtmlDoc .getURL (
1100+ "https://fonts.googleapis.com/css2?family=Playfair+Display:ital,wght@0,400..900;1,400..900&family=Raleway:wght@200&display=swap" )
1101+ .toExternalForm ());
1102+
1103+ // Web browsers admit the following
1104+ assertEquals (
1105+ "https://fonts.googleapis.com/css?family=Roboto+Slab:400,700,300%7CRoboto:400,500,700,300,900&subset=latin,greek,greek-ext,vietnamese,cyrillic-ext,latin-ext,cyrillic" ,
1106+ xhtmlDoc .getURL (
1107+ "https://fonts.googleapis.com/css?family=Roboto+Slab:400,700,300|Roboto:400,500,700,300,900&subset=latin,greek,greek-ext,vietnamese,cyrillic-ext,latin-ext,cyrillic" )
1108+ .toExternalForm ());
1109+
1110+ assertThrows (MalformedURLException .class , () -> xhtmlDoc .getURL ("https:||www.example.com/" ));
1111+
1112+ assertThrows (MalformedURLException .class ,
1113+ () -> xhtmlDoc .getURL ("https://www.example.com/a?b=c\\ d" ));
1114+
1115+ assertThrows (MalformedURLException .class ,
1116+ () -> xhtmlDoc .getURL ("https://www.example.com/a?b=\" c\" " ));
1117+
10911118 // Wrong URL
10921119 base .setAttribute ("href" , "http//" );
10931120 assertNull (xhtmlDoc .getBaseURI ());
@@ -1119,6 +1146,7 @@ public void testBaseElement2() throws MalformedURLException {
11191146 // Set documentURI and then unsafe attribute
11201147 xhtmlDoc .setDocumentURI ("http://www.example.com/doc-uri" );
11211148 CSSElement base = (CSSElement ) xhtmlDoc .getElementsByTagName ("base" ).item (0 );
1149+
11221150 // Relative URL
11231151 base .setAttribute ("href" , "foo" );
11241152 assertEquals ("foo" , base .getAttribute ("href" ));
0 commit comments