From d62de1e44a078e8b3fbb81759a8593ddd85bfd19 Mon Sep 17 00:00:00 2001 From: Stefan Erichsen Date: Thu, 4 Jan 2018 18:56:10 +0100 Subject: [PATCH] added detection for server relative URLs --- .../org/xhtmlrenderer/css/parser/CSSParser.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/flying-saucer-core/src/main/java/org/xhtmlrenderer/css/parser/CSSParser.java b/flying-saucer-core/src/main/java/org/xhtmlrenderer/css/parser/CSSParser.java index 7bcfc9b3e..19e2d9e27 100644 --- a/flying-saucer-core/src/main/java/org/xhtmlrenderer/css/parser/CSSParser.java +++ b/flying-saucer-core/src/main/java/org/xhtmlrenderer/css/parser/CSSParser.java @@ -1951,6 +1951,12 @@ private String getTokenValue(Token t, boolean literal) { if (lastSlash != -1) { uriResult = _URI.substring(0, lastSlash+1) + uriResult; } + } else if (isServerRelativeURI(uriResult)) { + int uriOffset = _URI.indexOf("://") + 3; + int firstSlashAfterProtocol = _URI.substring(uriOffset).indexOf('/'); + if (firstSlashAfterProtocol != -1) { + uriResult = _URI.substring(0, uriOffset + firstSlashAfterProtocol) + uriResult; + } } return uriResult; @@ -1980,6 +1986,14 @@ private boolean isRelativeURI(String uri) { } } + private boolean isServerRelativeURI(String uri) { + try { + return uri.length() > 0 && uri.charAt(0) == '/' && !new URI(uri).isAbsolute(); + } catch (URISyntaxException e) { + return false; + } + } + private int getCurrentLine() { return _lexer.yyline(); }