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", () => {
163
163
expect ( el . childAt ( 0 ) . children ( ) ) . toHaveLength ( 3 ) ;
164
164
} ) ;
165
165
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
+
166
196
describe ( "useClasses options" , ( ) => {
167
197
test ( "can add the font color class" , ( ) => {
168
198
const el = shallow (
Original file line number Diff line number Diff line change @@ -101,12 +101,12 @@ function convertBundleIntoReact(
101
101
}
102
102
103
103
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;
105
105
106
106
let index = 0 ;
107
107
let match : RegExpExecArray | null ;
108
108
while ( ( match = linkRegex . exec ( bundle . content ) ) !== null ) {
109
- const [ , pre , url , post ] = match ;
109
+ const [ , pre , url ] = match ;
110
110
111
111
const startIndex = match . index + pre . length ;
112
112
if ( startIndex > index ) {
@@ -128,8 +128,7 @@ function convertBundleIntoReact(
128
128
)
129
129
) ;
130
130
131
- const endIndex = linkRegex . lastIndex - post . length ;
132
- index = endIndex ;
131
+ index = linkRegex . lastIndex ;
133
132
}
134
133
135
134
if ( index < bundle . content . length ) {
You can’t perform that action at this time.
0 commit comments