[hg] main-silver: #222534 - Class name "http::request" is highli...

  • From: Milutin Kristofic < >
  • To:
  • Subject: [hg] main-silver: #222534 - Class name "http::request" is highli...
  • Date: Tue, 04 Dec 2012 10:55:06 -0800

changeset 5b52dd7f7ee3 in main-silver ((none))
details: http://hg.netbeans.org/main-silver/rev/5b52dd7f7ee3
description:
        #222534 - Class name "http::request" is highlighted as a hyperlink

diffstat:

 editor/src/org/netbeans/modules/editor/url/Parser.java               |  65 
++++++---
 editor/test/unit/src/org/netbeans/modules/editor/url/ParserTest.java |   9 +-
 2 files changed, 47 insertions(+), 27 deletions(-)

diffs (161 lines):

diff --git a/editor/src/org/netbeans/modules/editor/url/Parser.java 
b/editor/src/org/netbeans/modules/editor/url/Parser.java
--- a/editor/src/org/netbeans/modules/editor/url/Parser.java
+++ b/editor/src/org/netbeans/modules/editor/url/Parser.java
@@ -54,17 +54,26 @@
  */
 public final class Parser {
 
+    private enum STATE {
+        START, H, HT, F, HTT_FT, 
+        HTTP_FTP,
+        HTTPS,
+        HTTPC, // // (ht|f)tp(s?)
+        HTTPCS, // (ht|f)tp(s?):/
+        END // (ht|f)tp(s?)://
+    }
+
     private Parser() {}
 
     public static Iterable<int[]> recognizeURLs(CharSequence text) {
         List<int[]> result = new LinkedList<int[]>();
-        int state = 0;
+        STATE state = STATE.START;
         int lastURLStart = -1;
         
         OUTER: for (int cntr = 0; cntr < text.length(); cntr++) {
             char ch = text.charAt(cntr);
 
-            if (state == 6) {
+            if (state == STATE.END) {
                 if (Character.isLetterOrDigit(ch)) {
                     continue OUTER;
                 }
@@ -81,72 +90,78 @@
                 result.add(new int[] {lastURLStart, cntr});
 
                 lastURLStart = (-1);
-                state = 0;
+                state = STATE.START;
                 continue OUTER;
             }
 
             switch (ch) {
                 case 'h': //NOI18N
-                    if (state == 0) {
+                    if (state == STATE.START) {
                         lastURLStart = cntr;
-                        state = 1;
+                        state = STATE.H;
                         continue OUTER;
                     }
                     break;
                 case 't': //NOI18N
-                    if (state == 1) {
-                        state = 2;
+                    if (state == STATE.H) {
+                        state = STATE.HT;
                         continue OUTER;
-                    } else if (state == 2) {
-                            state = 3;
+                    } else if (state == STATE.HT) {
+                            state = STATE.HTT_FT;
                             continue OUTER;
-                    } else if (state == 7) {
-                        state = 8;
+                    } else if (state == STATE.F) {
+                        state = STATE.HTT_FT;
                         continue OUTER;
                     }
                     break;
                 case 'f': //NOI18N
-                    if (state == 0) {
+                    if (state == STATE.START) {
                         lastURLStart = cntr;
-                        state = 7;
+                        state = STATE.F;
                         continue OUTER;
                     }
                     break;
                 case 'p': //NOI18N
-                    if (state == 3) {
-                        state = 4;
-                        continue OUTER;
-                    } else if (state == 8) {
-                        state = 5;
+                    if (state == STATE.HTT_FT) {
+                        state = STATE.HTTP_FTP;
                         continue OUTER;
                     }
                     break;
                 case 's': //NOI18N
-                    if (state == 4) {
-                        state = 5;
+                    if (state == STATE.HTTP_FTP) {
+                        state = STATE.HTTPS;
                         continue OUTER;
                     }
                     break;
                 case ':': //NOI18N
-                    if (state == 4 || state == 5) {
-                        state = 6;
+                    if (state == STATE.HTTP_FTP || state == STATE.HTTPS) {
+                        state = STATE.HTTPC;
+                        continue OUTER;
+                    }
+                    break;
+                case '/' : //NOI18N
+                    if (state == STATE.HTTPC) {
+                        state = STATE.HTTPCS;
+                        continue OUTER;
+                    } else if (state == STATE.HTTPCS) {
+                        state = STATE.END;
                         continue OUTER;
                     }
                     break;
             }
 
-            state = 0;
+            state = STATE.START;
             lastURLStart = (-1);
         }
 
-        if (lastURLStart != (-1) && state == 6) {
+        if (lastURLStart != (-1) && state == STATE.END) {
             result.add(new int[] {lastURLStart, text.length()});
         }
         
         return result;
     }
     
-    private static final Pattern URL_PATTERN = 
Pattern.compile("(https|http|ftp):[0-9a-zA-Z/.?%+_~=\\\\&$\\-#,:]*"); //NOI18N
+    private static final Pattern URL_PATTERN = 
Pattern.compile("(ht|f)tp(s?)://[0-9a-zA-Z/.?%+_~=\\\\&$\\-#,:]*"); //NOI18N
 
     public static Iterable<int[]> recognizeURLsREBased(CharSequence text) {
         Matcher m = URL_PATTERN.matcher(text);
diff --git 
a/editor/test/unit/src/org/netbeans/modules/editor/url/ParserTest.java 
b/editor/test/unit/src/org/netbeans/modules/editor/url/ParserTest.java
--- a/editor/test/unit/src/org/netbeans/modules/editor/url/ParserTest.java
+++ b/editor/test/unit/src/org/netbeans/modules/editor/url/ParserTest.java
@@ -82,9 +82,9 @@
         performTest("    https://www.netbeans.org/~s?d=3_\n", 4, 36);
         performTest("    https://www.test-test.test/\n", 4, 31);
         performTest("    https://www.test-test.test/a.jsp?tt\\&t$=$\n", 4, ;
45);
-        performTest("    ftps://www.test-test.test/a.jsp?tt\\&t$=$\n", null);
+        performTest("    ftps://www.test-test.test/a.jsp?tt\\&t$=$\n", 4, 
44);
         performTest("    f t p://www.test-test.test/a.jsp?tt\\&t$=$\n", 
null);
-        performTest("    ftps://www.test-test.test/a.jsp?tt\\&t$=$", null);
+        performTest("    ftps://www.test-test.test/a.jsp?tt\\&t$=$", 4, 44);
         performTest("    \"https://www.netbeans.org/\"", 5, 30);
         performTest("    https://some.where/some-thing.html#section\n", 4, ;
46);
         performTest("    
https://netbeans.org/bugzilla/buglist.cgi?bug_id=181772,172312\n", 4, 66);
@@ -101,6 +101,11 @@
     }
 
     @Test
+    public void testInvalidUrls() {
+        performTest("    http::request\n", null);
+    }
+
+    @Test
     public void testContentType() {
         assertEquals("ISO-8859-2", Parser.decodeContentType("text/html; 
charset=ISO-8859-2"));
         assertEquals("ISO-8859-2", Parser.decodeContentType("text/html; 
charset=ISO-8859-2;"));

[hg] main-silver: #222534 - Class name "http::request" is highli...

Milutin Kristofic 12/04/2012

Project Features

About this Project

Editor was started in November 2009, is owned by Martin Ryzl, and has 147 members.
By use of this website, you agree to the NetBeans Policies and Terms of Use (revision 20131025.e7cbc9d). © 2013, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo
 
 
Close
loading
Please Confirm
Close