incubator-wave-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yur...@apache.org
Subject svn commit: r1307322 - in /incubator/wave/trunk: src/org/waveprotocol/wave/client/doodad/link/Link.java test/org/waveprotocol/wave/client/doodad/link/LinkTest.java
Date Fri, 30 Mar 2012 09:06:58 GMT
Author: yurize
Date: Fri Mar 30 09:06:58 2012
New Revision: 1307322

URL: http://svn.apache.org/viewvc?rev=1307322&view=rev
Log:
Allows #fragments in links. By By Vicente J. Ruiz Jurado https://reviews.apache.org/r/4228

Modified:
    incubator/wave/trunk/src/org/waveprotocol/wave/client/doodad/link/Link.java
    incubator/wave/trunk/test/org/waveprotocol/wave/client/doodad/link/LinkTest.java

Modified: incubator/wave/trunk/src/org/waveprotocol/wave/client/doodad/link/Link.java
URL: http://svn.apache.org/viewvc/incubator/wave/trunk/src/org/waveprotocol/wave/client/doodad/link/Link.java?rev=1307322&r1=1307321&r2=1307322&view=diff
==============================================================================
--- incubator/wave/trunk/src/org/waveprotocol/wave/client/doodad/link/Link.java (original)
+++ incubator/wave/trunk/src/org/waveprotocol/wave/client/doodad/link/Link.java Fri Mar 30
09:06:58 2012
@@ -39,6 +39,14 @@ public final class Link {
 
   private static final ReadableStringSet WEB_SCHEMES = CollectionUtils.newStringSet(
       "http", "https", "ftp", "mailto");
+  /**
+   * http://en.wikipedia.org/wiki/Fragment_identifier
+   * http://tools.ietf.org/html/rfc3986#section-3.5
+   * fragment    = *( pchar / "/" / "?" )
+   */
+  private static final String COMMON_REGEX = "[\\w\\-:@!\\$&\'\\(\\)\\*\\+,;=\\/\\?\\.]+";
+  private static final String FRAGMENT_URI_REGEX = "#(" + COMMON_REGEX + "|$)";
+  private static final String QUERY_REGEX = "(\\?" + COMMON_REGEX +"|)($|"+ FRAGMENT_URI_REGEX
+ ")";
 
   private static final String INVALID_LINK_MSG =
       "Invalid link. Should either be a web url\n" +
@@ -125,7 +133,7 @@ public final class Link {
       }
     }
 
-    assert EscapeUtils.extractScheme(uri) != null;
+    assert uri.matches(QUERY_REGEX) || EscapeUtils.extractScheme(uri) != null;
 
     // Otherwise, just return the given link.
     return uri;
@@ -145,7 +153,7 @@ public final class Link {
     String scheme = parts != null ? parts[0] : null;
 
     // Normal web url
-    if (scheme != null && WEB_SCHEMES.contains(scheme)) {
+    if (rawLinkValue.matches(QUERY_REGEX) || (scheme != null && WEB_SCHEMES.contains(scheme)))
{
       return rawLinkValue;
     }
 

Modified: incubator/wave/trunk/test/org/waveprotocol/wave/client/doodad/link/LinkTest.java
URL: http://svn.apache.org/viewvc/incubator/wave/trunk/test/org/waveprotocol/wave/client/doodad/link/LinkTest.java?rev=1307322&r1=1307321&r2=1307322&view=diff
==============================================================================
--- incubator/wave/trunk/test/org/waveprotocol/wave/client/doodad/link/LinkTest.java (original)
+++ incubator/wave/trunk/test/org/waveprotocol/wave/client/doodad/link/LinkTest.java Fri Mar
30 09:06:58 2012
@@ -47,6 +47,15 @@ public class LinkTest extends TestCase {
     checkNormalize("https://example.com/abcd");
     checkNormalize("ftp://example.com/abcd");
     checkNormalize("mailto://example.com/abcd");
+    checkNormalize("#");
+    checkNormalize("#example.com/w+N0tgD7rctjA");
+    checkNormalize("#fragment");
+    checkNormalize("#fragment/?+-:@!$&'()*+,;=");
+    checkNormalize("?param=1&param2");
+    checkNormalize("?param=1&param2#");
+    checkNormalize("?param=1&param2#fragment/?+-:@!$&'()*+,;=");
+    checkNormalizeRejects("#fragment<>");
+    checkNormalizeRejects("?param=1&param2<>");
   }
 
   public void testConvertUri() {
@@ -56,6 +65,12 @@ public class LinkTest extends TestCase {
 
     assertEquals("http://example.com/abcd", Link.toHrefFromUri("http://example.com/abcd"));
     assertEquals("#example.com/abcd", Link.toHrefFromUri("wave://example.com/abcd"));
+    assertEquals("#", Link.toHrefFromUri("#"));
+    assertEquals("#fragment", Link.toHrefFromUri("#fragment"));
+    assertEquals("#fragment/?+-:@!$&'()*+,;=", Link.toHrefFromUri("#fragment/?+-:@!$&'()*+,;="));
+    assertEquals("?param=1&param2", Link.toHrefFromUri("?param=1&param2"));
+    assertEquals("?param=1&param2#", Link.toHrefFromUri("?param=1&param2#"));
+    assertEquals("?param=1&param2#fragment/?+-:@!$&'()*+,;=", Link.toHrefFromUri("?param=1&param2#fragment/?+-:@!$&'()*+,;="));
   }
 
 



Mime
View raw message