From: <bra...@us...> - 2009-11-11 00:33:39
|
Revision: 2926 http://archive-access.svn.sourceforge.net/archive-access/?rev=2926&view=rev Author: bradtofel Date: 2009-11-11 00:18:08 +0000 (Wed, 11 Nov 2009) Log Message: ----------- BUGFIX(unreported) URI actually does not do proper path canonicalization - resolving "../../foo.gif" against "http://base.com/" results in "http://base.com/../../foo.gif" not "http://base.com/foo.gif" as it should. UURI does the right thing, so now this uses UURI to perform the resolving, and now we have a trivial test case that demonstrates this. Modified Paths: -------------- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/replay/html/ReplayParseContext.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/util/htmllex/ParseContext.java Added Paths: ----------- trunk/archive-access/projects/wayback/wayback-core/src/test/java/org/archive/wayback/util/htmllex/ trunk/archive-access/projects/wayback/wayback-core/src/test/java/org/archive/wayback/util/htmllex/ParseContextTest.java Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/replay/html/ReplayParseContext.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/replay/html/ReplayParseContext.java 2009-11-11 00:14:29 UTC (rev 2925) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/replay/html/ReplayParseContext.java 2009-11-11 00:18:08 UTC (rev 2926) @@ -46,7 +46,7 @@ URL baseUrl, String datespec) { this.uriConverterFactory = uriConverterFactory; - this.baseUrl = baseUrl; + setBaseUrl(baseUrl); this.datespec = datespec; converters = new HashMap<String,ResultURIConverter>(); } @@ -143,4 +143,18 @@ public void setJspExec(JSPExecutor jspExec) { this.jspExec = jspExec; } + + /** + * @return the datespec + */ + public String getDatespec() { + return datespec; + } + + /** + * @param datespec the datespec to set + */ + public void setDatespec(String datespec) { + this.datespec = datespec; + } } Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/util/htmllex/ParseContext.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/util/htmllex/ParseContext.java 2009-11-11 00:14:29 UTC (rev 2925) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/util/htmllex/ParseContext.java 2009-11-11 00:18:08 UTC (rev 2926) @@ -28,6 +28,10 @@ import java.net.URL; import java.util.HashMap; +import org.apache.commons.httpclient.URIException; +import org.archive.net.UURI; +import org.archive.net.UURIFactory; + /** * Class which tracks the context and state involved with parsing an HTML * document via SAX events. @@ -43,7 +47,7 @@ */ public class ParseContext { - protected URL baseUrl = null; + protected UURI baseUrl = null; private boolean inCSS = false; private boolean inJS = false; @@ -60,11 +64,21 @@ return data.get(key); } public void setBaseUrl(URL url) { - baseUrl = url; + try { + baseUrl = UURIFactory.getInstance(url.toExternalForm()); + } catch (URIException e) { + e.printStackTrace(); + } } public String resolve(String url) throws MalformedURLException { - URL tmp = new URL(baseUrl,url); - return tmp.toString(); + try { + return baseUrl.resolve(url).toString(); + } catch (URIException e) { + e.printStackTrace(); + } + return url; +// URL tmp = new URL(baseUrl,url); +// return tmp.toString(); } public String contextualizeUrl(String url) { if(url.startsWith("javascript:")) { Added: trunk/archive-access/projects/wayback/wayback-core/src/test/java/org/archive/wayback/util/htmllex/ParseContextTest.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/test/java/org/archive/wayback/util/htmllex/ParseContextTest.java (rev 0) +++ trunk/archive-access/projects/wayback/wayback-core/src/test/java/org/archive/wayback/util/htmllex/ParseContextTest.java 2009-11-11 00:18:08 UTC (rev 2926) @@ -0,0 +1,68 @@ +/* ParseContextTest + * + * $Id$: + * + * Created on Nov 10, 2009. + * + * Copyright (C) 2006 Internet Archive. + * + * This file is part of Wayback. + * + * Wayback is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * any later version. + * + * Wayback is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser Public License for more details. + * + * You should have received a copy of the GNU Lesser Public License + * along with Wayback; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +package org.archive.wayback.util.htmllex; + +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URL; + +import org.archive.net.UURI; +import org.archive.net.UURIFactory; + +import junit.framework.TestCase; + +/** + * @author brad + * + */ +public class ParseContextTest extends TestCase { + + /** + * Test method for {@link org.archive.wayback.util.htmllex.ParseContext#contextualizeUrl(java.lang.String)}. + */ + public void testContextualizeUrl() { + ParseContext pc = new ParseContext(); + try { + pc.setBaseUrl(new URL("http://base.com/")); + assertEquals("http://base.com/images.gif", + pc.contextualizeUrl("/images.gif")); + assertEquals("http://base.com/images.gif", + pc.contextualizeUrl("../images.gif")); + assertEquals("http://base.com/images.gif", + pc.contextualizeUrl("../../images.gif")); + assertEquals("http://base.com/image/1s.gif", + pc.contextualizeUrl("/image/1s.gif")); + assertEquals("http://base.com/image/1s.gif", + pc.contextualizeUrl("../../image/1s.gif")); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + fail(e.getLocalizedMessage()); + } + + } + +} Property changes on: trunk/archive-access/projects/wayback/wayback-core/src/test/java/org/archive/wayback/util/htmllex/ParseContextTest.java ___________________________________________________________________ Added: svn:keywords + Author Date Revision Id This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |