File tree Expand file tree Collapse file tree 2 files changed +33
-4
lines changed Expand file tree Collapse file tree 2 files changed +33
-4
lines changed Original file line number Diff line number Diff line change @@ -163,6 +163,36 @@ describe("Ansi", () => {
163163 expect ( el . childAt ( 0 ) . children ( ) ) . toHaveLength ( 3 ) ;
164164 } ) ;
165165
166+ test ( "can linkify multiple links one after another" , ( ) => {
167+ const el = shallow (
168+ React . createElement (
169+ Ansi ,
170+ { linkify : true } ,
171+ "www.google.com www.google.com www.google.com"
172+ )
173+ ) ;
174+ expect ( el ) . not . toBeNull ( ) ;
175+ expect ( el . text ( ) ) . toBe ( "www.google.com www.google.com www.google.com" ) ;
176+ expect ( el . html ( ) ) . toBe (
177+ '<code><span><a href="http://www.google.com" target="_blank">www.google.com</a> <a href="http://www.google.com" target="_blank">www.google.com</a> <a href="http://www.google.com" target="_blank">www.google.com</a></span></code>'
178+ ) ;
179+ } ) ;
180+
181+ test ( "can handle URLs inside query parameters" , ( ) => {
182+ const el = shallow (
183+ React . createElement (
184+ Ansi ,
185+ { linkify : true } ,
186+ "www.google.com/?q=https://www.google.com"
187+ )
188+ ) ;
189+ expect ( el ) . not . toBeNull ( ) ;
190+ expect ( el . text ( ) ) . toBe ( "www.google.com/?q=https://www.google.com" ) ;
191+ expect ( el . html ( ) ) . toBe (
192+ '<code><span><a href="http://www.google.com/?q=https://www.google.com" target="_blank">www.google.com/?q=https://www.google.com</a></span></code>'
193+ ) ;
194+ } ) ;
195+
166196 describe ( "useClasses options" , ( ) => {
167197 test ( "can add the font color class" , ( ) => {
168198 const el = shallow (
Original file line number Diff line number Diff line change @@ -101,12 +101,12 @@ function convertBundleIntoReact(
101101 }
102102
103103 const content : React . ReactNode [ ] = [ ] ;
104- const linkRegex = / ( \s + | ^ ) ( h t t p s ? : \/ \/ (?: w w w \. | (? ! w w w ) ) [ ^ \s . ] + \. [ ^ \s ] { 2 , } | w w w \. [ ^ \s ] + \. [ ^ \s ] { 2 , } ) ( \s + | $ ) / g;
104+ const linkRegex = / ( \s + | ^ ) ( h t t p s ? : \/ \/ (?: w w w \. | (? ! w w w ) ) [ ^ \s . ] + \. [ ^ \s ] { 2 , } | w w w \. [ ^ \s ] + \. [ ^ \s ] { 2 , } ) / g;
105105
106106 let index = 0 ;
107107 let match : RegExpExecArray | null ;
108108 while ( ( match = linkRegex . exec ( bundle . content ) ) !== null ) {
109- const [ , pre , url , post ] = match ;
109+ const [ , pre , url ] = match ;
110110
111111 const startIndex = match . index + pre . length ;
112112 if ( startIndex > index ) {
@@ -128,8 +128,7 @@ function convertBundleIntoReact(
128128 )
129129 ) ;
130130
131- const endIndex = linkRegex . lastIndex - post . length ;
132- index = endIndex ;
131+ index = linkRegex . lastIndex ;
133132 }
134133
135134 if ( index < bundle . content . length ) {
You can’t perform that action at this time.
0 commit comments