From 5159eb76350a4da587bab3d73e212ed134cde789 Mon Sep 17 00:00:00 2001
From: Misko Hevery
Date: Tue, 2 Nov 2010 18:39:30 -0700
Subject: fix the linky filter
---
 .idea/projectCodeStyle.xml               |   9 ++
 .idea/runConfigurations/gen_docs.xml     |   2 +-
 .idea/runConfigurations/rake_compile.xml |   2 +-
 .idea/workspace.xml                      | 211 ++++++++++++++++++++++++++++---
 docs/docs-scenario.html                  |   1 +
 src/filters.js                           |  32 +++--
 src/scenario/dsl.js                      |   1 -
 test.sh                                  |   1 +
 test/FiltersSpec.js                      |   9 +-
 9 files changed, 234 insertions(+), 34 deletions(-)
diff --git a/.idea/projectCodeStyle.xml b/.idea/projectCodeStyle.xml
index a5c450f7..e9f2d7f2 100644
--- a/.idea/projectCodeStyle.xml
+++ b/.idea/projectCodeStyle.xml
@@ -24,6 +24,15 @@
           
           
         
+        
+          
+          
+          
+          
+          
+          
+          
+        
         
           
           
diff --git a/.idea/runConfigurations/gen_docs.xml b/.idea/runConfigurations/gen_docs.xml
index 23afac13..f868b817 100644
--- a/.idea/runConfigurations/gen_docs.xml
+++ b/.idea/runConfigurations/gen_docs.xml
@@ -5,7 +5,7 @@
     
     
     
-    
+    
     
     
     
diff --git a/.idea/runConfigurations/rake_compile.xml b/.idea/runConfigurations/rake_compile.xml
index d69f3466..fa79475d 100644
--- a/.idea/runConfigurations/rake_compile.xml
+++ b/.idea/runConfigurations/rake_compile.xml
@@ -5,7 +5,7 @@
     
     
     
-    
+    
     
     
     
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 62adcd33..355943e1 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -1,7 +1,11 @@
 
 
   
-    
+
+      
+      
+      
+    
@@ -23,7 +27,88 @@
   
   
   
-    
+    
+      
+        
+          
+            
+              
+                
+                  
+                
+              
+            
+          
+          
+            
+              
+                
+                  
+                
+              
+            
+          
+          
+            
+              
+                
+                  
+                
+              
+            
+          
+          
+            
+              
+                
+                  
+                
+              
+            
+          
+          
+            
+              
+                
+                  
+                
+              
+            
+          
+          
+            
+              
+                
+                  
+                
+              
+            
+          
+          
+            
+              
+                
+                  
+                
+              
+            
+          
+        
+      
+      
+        
+          
+            
+              
+                
+                  
+                
+              
+            
+          
+        
+      
+    
   
   
     
@@ -40,6 +125,11 @@
         
         
         
+        
+        
+        
+        
+        
       
     
   
@@ -69,8 +159,6 @@
       
     
     
-      
-      
       
         
           
@@ -89,6 +177,20 @@
               
             
           
+          
+            
+              
+              
+            
+            
+              
+              
+            
+            
+              
+              
+            
+          
           
             
               
@@ -145,6 +247,8 @@
           
         
       
+      
+      
     
   
   
@@ -156,7 +260,7 @@
     
     
   
-  
+  
     
       
       
@@ -170,6 +274,19 @@
       
       
     
+    
+      
+      
+      
+      
+      
+      
+      
+      
+      
+      
+      
+    
     
       
       
@@ -181,8 +298,11 @@
       
       
     
-
+    
       +
+
+
@@ -213,21 +333,21 @@
   
   
     
-    
+    
     
-      
-      
+      
       
       
       
       
       
-      
+      
       
       
       
       
       
+      
       
       
       
@@ -276,9 +396,7 @@
   
     
       
-        
-          
-        
+        
       
     
     
@@ -304,9 +422,7 @@
     
     
       
-        
-          
-        
+        
       
     
     
@@ -316,6 +432,69 @@
         
       
     
+    
+      
+        
+          
+        
+      
+    
+    
+      
+        
+          
+        
+      
+    
+    
+      
+        
+          
+        
+      
+    
+    
+      
+        
+          
+        
+      
+    
+    
+      
+        
+          
+        
+      
+    
+    
+      
+        
+          
+        
+      
+    
+    
+      
+        
+          
+        
+      
+    
+    
+      
+        
+          
+        
+      
+    
+    
+      
+        
+          
+        
+      
+    
   
 
 
diff --git a/docs/docs-scenario.html b/docs/docs-scenario.html
index 83ca6fdf..c75155c5 100644
--- a/docs/docs-scenario.html
+++ b/docs/docs-scenario.html
@@ -1,6 +1,7 @@
 
 
 
+  <angular/> Docs Scenario Runner
   
   
 
diff --git a/src/filters.js b/src/filters.js
index 64d8c8ba..0cff6d56 100644
--- a/src/filters.js
+++ b/src/filters.js
@@ -360,7 +360,8 @@ angularFilter.html =  function(html, option){
  * @function
  *
  * @description
- *   Finds links in text input and turns them into html links. Supports http/https/ftp/mailto links.
+ *   Finds links in text input and turns them into html links. Supports http/https/ftp/mailto and
+ *   plane email address links.
  *
  * @param {string} text Input text.
  * @returns {string} Html-linkified text.
@@ -369,7 +370,8 @@ angularFilter.html =  function(html, option){
      Snippet:
        
@@ -392,13 +394,14 @@ and one more: ftp://127.0.0.1/.
          |  | 
      
-
+ *
  * @scenario
      it('should linkify the snippet with urls', function(){
        expect(using('#linky-filter').binding('snippet | linky')).
          toBe('Pretty text with some links:\n' +
-              'http://angularjs.org/,' +
-              'mailto:us@somewhere.org\n' +
+              'http://angularjs.org/,\n' +
+              'us@somewhere.org,\n' +
+              'another@somewhere.org,\n' +
               'and one more: ftp://127.0.0.1/.');
      });
 
@@ -406,7 +409,8 @@ and one more: ftp://127.0.0.1/.
        expect(using('#escaped-html').binding('snippet')).
          toBe("Pretty text with some links:\n" +
               "http://angularjs.org/,\n" +
-              "mailto:us@somewhere.org\n" +
+              "mailto:us@somewhere.org,\n" +
+              "another@somewhere.org,\n" +
               "and one more: ftp://127.0.0.1/.");
      });
 
@@ -420,10 +424,7 @@ and one more: ftp://127.0.0.1/.
 //TODO: externalize all regexps
 angularFilter.linky = function(text){
   if (!text) return text;
-  function regExpEscape(text) {
-    return text.replace(/([\/\.\*\+\?\|\(\)\[\]\{\}\\])/g, '\\$1');
-  }
-  var URL = /(ftp|http|https|mailto):\/\/([^\(\)|\s]+)/;
+  var URL = /((ftp|https?):\/\/|(mailto:)?[A-Za-z0-9._%+-]+@)\S*[^\s\.\;\,\(\)\{\}\<\>]/;
   var match;
   var raw = text;
   var html = [];
@@ -431,13 +432,16 @@ angularFilter.linky = function(text){
   var url;
   var i;
   while (match=raw.match(URL)) {
-    url = match[0].replace(/[\.\;\,\(\)\{\}\<\>]$/,'');
-    i = raw.indexOf(url);
+    // We can not end in these as they are sometimes found at the end of the sentence
+    url = match[0];
+    // if we did not match ftp/http/mailto then assume mailto
+    if (match[2]==match[3]) url = 'mailto:' + url;
+    i = match.index;
     writer.chars(raw.substr(0, i));
     writer.start('a', {href:url});
-    writer.chars(url);
+    writer.chars(match[0].replace(/^mailto:/, ''));
     writer.end('a');
-    raw = raw.substring(i + url.length);
+    raw = raw.substring(i + match[0].length);
   }
   writer.chars(raw);
   return new HTML(html.join(''));
diff --git a/src/scenario/dsl.js b/src/scenario/dsl.js
index 45156369..f37ab71d 100644
--- a/src/scenario/dsl.js
+++ b/src/scenario/dsl.js
@@ -170,7 +170,6 @@ angular.scenario.dsl('binding', function() {
           if (element.is('input, textarea')) {
             done(null, element.val());
           } else {
-            console.log('element.html(): ', element.html());
             done(null, element.html());
           }
           return;
diff --git a/test.sh b/test.sh
index 19a74d4b..91876310 100755
--- a/test.sh
+++ b/test.sh
@@ -1,3 +1,4 @@
+#!/bin/sh
 tests=$1
 if [[ $tests = "" ]]; then
   tests="all"
diff --git a/test/FiltersSpec.js b/test/FiltersSpec.js
index 4dd108ac..0de7b5b7 100644
--- a/test/FiltersSpec.js
+++ b/test/FiltersSpec.js
@@ -74,8 +74,8 @@ describe('filter', function(){
   });
 
   describe('Linky', function() {
+    var linky = filter.linky;
     it('should do basic filter', function(){
-      var linky = filter.linky;
       assertEquals(
           'http://ab/ ' +
           '(http://a/) ' +
@@ -84,6 +84,13 @@ describe('filter', function(){
           linky("http://ab/ (http://a/)  http://1.2/v:~-123. c").html);
       assertEquals(undefined, linky(undefined));
     });
+
+    it('should handle mailto:', function(){
+      expect(linky("mailto:me@example.com").html).toEqual('me@example.com');
+      expect(linky("me@example.com").html).toEqual('me@example.com');
+      expect(linky("send email to me@example.com, but").html).
+        toEqual('send email to me@example.com, but');
+    });
   });
 
   describe('date', function(){
-- 
cgit v1.2.3