Author: ltheussl
Date: Tue Jul 17 13:49:23 2007
New Revision: 557053
URL: http://svn.apache.org/viewvc?view=rev&rev=557053
Log:
Don't use file.separatorChar when testing for external link. Only unix-style
separators '/' are allowed in URIs.
Added:
maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/sink/StructureSinkTest.java
(with props)
Modified:
maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/sink/StructureSink.java
Modified:
maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/sink/StructureSink.java
URL:
http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/sink/StructureSink.java?view=diff&rev=557053&r1=557052&r2=557053
==============================================================================
---
maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/sink/StructureSink.java
(original)
+++
maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/sink/StructureSink.java
Tue Jul 17 13:49:23 2007
@@ -23,12 +23,22 @@
public class StructureSink
{
- public static boolean isExternalLink( String text )
+ /**
+ * Checks if the given string corresponds to an external URI,
+ * ie is not a link within the same document.
+ * @param link The link to check.
+ * @return True if the link (ignoring case) starts with either of the
+ * following: "http:/", "https:/", "ftp:/", "mailto:", "file:/",
+ * "../" or "./". Note that Windows style separators "\" are not allowed
+ * for URIs, see http://www.ietf.org/rfc/rfc2396.txt , section 2.4.3.
+ */
+ public static boolean isExternalLink( String link )
{
- text = text.toLowerCase();
+ String text = link.toLowerCase();
+
return ( text.indexOf( "http:/" ) == 0 || text.indexOf( "https:/" ) ==
0 || text.indexOf( "ftp:/" ) == 0 ||
text.indexOf( "mailto:" ) == 0 || text.indexOf( "file:/" ) == 0 ||
- text.indexOf( ".." + File.separatorChar ) == 0 || text.indexOf(
"." + File.separatorChar ) == 0 );
+ text.indexOf( "../" ) == 0 || text.indexOf( "./" ) == 0 );
}
public static String linkToKey( String text )
Added:
maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/sink/StructureSinkTest.java
URL:
http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/sink/StructureSinkTest.java?view=auto&rev=557053
==============================================================================
---
maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/sink/StructureSinkTest.java
(added)
+++
maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/sink/StructureSinkTest.java
Tue Jul 17 13:49:23 2007
@@ -0,0 +1,78 @@
+package org.apache.maven.doxia.sink;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.codehaus.plexus.PlexusTestCase;
+
+/**
+ * Test for org.apache.maven.doxia.sink.StructureSink
+ */
+public class StructureSinkTest
+ extends PlexusTestCase
+{
+
+ /**
+ * Test for org.apache.maven.doxia.sink.StructureSink#isExternalLink
+ */
+ public void testIsExternalLink()
+ {
+ String link = "http://maven.apache.org/";
+ assertTrue( "Should be an external link: " + link,
+ StructureSink.isExternalLink( link ) );
+
+ link = "https://maven.apache.org/";
+ assertTrue( "Should be an external link: " + link,
+ StructureSink.isExternalLink( link ) );
+
+ link = "ftp:/maven.apache.org/";
+ assertTrue( "Should be an external link: " + link,
+ StructureSink.isExternalLink( link ) );
+
+ link = "mailto:[EMAIL PROTECTED]";
+ assertTrue( "Should be an external link: " + link,
+ StructureSink.isExternalLink( link ) );
+
+ link = "file:/index.html";
+ assertTrue( "Should be an external link: " + link,
+ StructureSink.isExternalLink( link ) );
+
+ link = "./index.html";
+ assertTrue( "Should be an external link: " + link,
+ StructureSink.isExternalLink( link ) );
+
+ link = "../index.html";
+ assertTrue( "Should be an external link: " + link,
+ StructureSink.isExternalLink( link ) );
+
+
+ link = "file:\\index.html";
+ assertFalse( "Should NOT be an external link: " + link,
+ StructureSink.isExternalLink( link ) );
+
+ link = ".\\index.html";
+ assertFalse( "Should NOT be an external link: " + link,
+ StructureSink.isExternalLink( link ) );
+
+ link = "..\\index.html";
+ assertFalse( "Should NOT be an external link: " + link,
+ StructureSink.isExternalLink( link ) );
+ }
+
+}
Propchange:
maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/sink/StructureSinkTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/sink/StructureSinkTest.java
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"