harold92 / flying-saucer

Automatically exported from code.google.com/p/flying-saucer
0 stars 0 forks source link

URLs with dot seqments aren't resolved #119

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
If your xhtml references an css file which contains an URL with dot segments 
these URL aren't resolved by flying-saucer. In my case this occurred when 
creating a PDF file. Example:

Content of a file 'sample.css' located in a webapp/css path:

.someClass {
  background-image: url(../img/bg.png);
}

xhtmlrenderer asks the server for the url
localhost:8080/webapp/css/../img/bg.png
instead of the resolved version
localhost:8080/webapp/img/bg.png

But the url specification expects the client (in this case flying-saucer) to 
resolve this url. See http://www.ietf.org/rfc/rfc3986, Chapter 5.2.4.  Remove 
Dot Segments.

I found an example how to resolve these URLs with java: 
http://www.devdaily.com/java/jwarehouse/commons-httpclient-4.0.3/httpclient/src/
main/java/org/apache/http/client/utils/URIUtils.java.shtml

The problem disappears after adding an 'removeDotSegments' method (inspired by 
this example) to org.xhtmlrenderer.swing.NaiveUserAgent and call it by 
resolveURI

    public String resolveURI(String uri) {
        if (uri == null)
            return null;
        uri = removeDotSegments(uri); // ADDED
        String ret = null;
        if (_baseURL == null) {// first try to set a base URL
...

I added the whole file as an attachment.

The problem occurs in the current development version (9).

Original issue reported on code.google.com by ockerb...@gmail.com on 21 Feb 2011 at 1:50

Attachments: