@@ -10,10 +10,29 @@ function comment(prefix, suffix) {
1010 return rx . test ( prefix + 'sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiIiwic291cmNlcyI6WyJmdW5jdGlvbiBmb28oKSB7XG4gY29uc29sZS5sb2coXCJoZWxsbyBJIGFtIGZvb1wiKTtcbiBjb25zb2xlLmxvZyhcIndobyBhcmUgeW91XCIpO1xufVxuXG5mb28oKTtcbiJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSJ9' + suffix )
1111}
1212
13- function commentWithCharSet ( prefix , suffix , sep ) {
14- sep = sep || ':' ;
13+ function commentWithCharSet ( prefix , suffix ) {
1514 var rx = convert . commentRegex ;
16- return rx . test ( prefix + 'sourceMappingURL=data:application/json;charset' + sep + 'utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiIiwic291cmNlcyI6WyJmdW5jdGlvbiBmb28oKSB7XG4gY29uc29sZS5sb2coXCJoZWxsbyBJIGFtIGZvb1wiKTtcbiBjb25zb2xlLmxvZyhcIndobyBhcmUgeW91XCIpO1xufVxuXG5mb28oKTtcbiJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSJ9' + suffix )
15+ return rx . test ( prefix + 'sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiIiwic291cmNlcyI6WyJmdW5jdGlvbiBmb28oKSB7XG4gY29uc29sZS5sb2coXCJoZWxsbyBJIGFtIGZvb1wiKTtcbiBjb25zb2xlLmxvZyhcIndobyBhcmUgeW91XCIpO1xufVxuXG5mb28oKTtcbiJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSJ9' + suffix )
16+ }
17+
18+ function commentURI ( prefix , suffix ) {
19+ var rx = convert . commentRegex ;
20+ return rx . test ( prefix + 'sourceMappingURL=data:application/json,%7B%22version%22%3A3%2C%22file%22%3A%22%22%2C%22sources%22%3A%5B%22function%20foo()%20%7B%0A%20console.log(%22hello%20I%20am%20foo%22)%3B%0A%20console.log(%22who%20are%20you%22)%3B%0A%7D%0A%0Afoo()%3B%0A%22%5D%2C%22names%22%3A%5B%5D%2C%22mappings%22%3A%22AAAA%22%7D' + suffix )
21+ }
22+
23+ function commentURIWithCharSet ( prefix , suffix ) {
24+ var rx = convert . commentRegex ;
25+ return rx . test ( prefix + 'sourceMappingURL=data:application/json;charset=utf-8,%7B%22version%22%3A3%2C%22file%22%3A%22%22%2C%22sources%22%3A%5B%22function%20foo()%20%7B%0A%20console.log(%22hello%20I%20am%20foo%22)%3B%0A%20console.log(%22who%20are%20you%22)%3B%0A%7D%0A%0Afoo()%3B%0A%22%5D%2C%22names%22%3A%5B%5D%2C%22mappings%22%3A%22AAAA%22%7D' + suffix )
26+ }
27+
28+ function commentWithoutMediaType ( prefix , suffix ) {
29+ var rx = convert . commentRegex ;
30+ return rx . test ( prefix + 'sourceMappingURL=data:;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiIiwic291cmNlcyI6WyJmdW5jdGlvbiBmb28oKSB7XG4gY29uc29sZS5sb2coXCJoZWxsbyBJIGFtIGZvb1wiKTtcbiBjb25zb2xlLmxvZyhcIndobyBhcmUgeW91XCIpO1xufVxuXG5mb28oKTtcbiJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSJ9' + suffix )
31+ }
32+
33+ function commentURIWithoutMediaType ( prefix , suffix ) {
34+ var rx = convert . commentRegex ;
35+ return rx . test ( prefix + 'sourceMappingURL=data:,%7B%22version%22%3A3%2C%22file%22%3A%22%22%2C%22sources%22%3A%5B%22function%20foo()%20%7B%0A%20console.log(%22hello%20I%20am%20foo%22)%3B%0A%20console.log(%22who%20are%20you%22)%3B%0A%7D%0A%0Afoo()%3B%0A%22%5D%2C%22names%22%3A%5B%5D%2C%22mappings%22%3A%22AAAA%22%7D' + suffix )
1736}
1837
1938// Source Map v2 Tests
@@ -28,15 +47,21 @@ test('comment regex old spec - @', function (t) {
2847 '\t/*@ ' , // multi line style with leading tab
2948 '/*@ ' , // multi line style with leading text
3049 ] . forEach ( function ( x ) {
31- t . ok ( comment ( x , '' ) , 'matches ' + x )
32- t . ok ( commentWithCharSet ( x , '' ) , 'matches ' + x + ' with charset' )
33- t . ok ( commentWithCharSet ( x , '' , '=' ) , 'matches ' + x + ' with charset' )
50+ t . ok ( comment ( x , '' ) , 'matches ' + x )
51+ t . ok ( commentWithCharSet ( x , '' ) , 'matches ' + x + ' with charset' )
52+ t . ok ( commentURI ( x , '' ) , 'matches ' + x + ' uri' )
53+ t . ok ( commentURIWithCharSet ( x , '' ) , 'matches ' + x + ' uri with charset' )
54+ t . ok ( commentWithoutMediaType ( x , '' ) , 'matches ' + x + ' without media type' )
55+ t . ok ( commentURIWithoutMediaType ( x , '' ) , 'matches ' + x + ' uri without media type' )
3456 } ) ;
3557
3658 [
3759 ' @// @' ,
3860 ' @/* @' ,
39- ] . forEach ( function ( x ) { t . ok ( ! comment ( x , '' ) , 'should not match ' + x ) } )
61+ ] . forEach ( function ( x ) {
62+ t . ok ( ! comment ( x , '' ) , 'should not match ' + x )
63+ t . ok ( ! commentURI ( x , '' ) , 'should not match ' + x + ' uri' )
64+ } )
4065
4166 t . end ( )
4267} )
@@ -51,15 +76,123 @@ test('comment regex new spec - #', function (t) {
5176 '\t/*# ' , // multi line style with leading tab
5277 '/*# ' , // multi line style with leading text
5378 ] . forEach ( function ( x ) {
54- t . ok ( comment ( x , '' ) , 'matches ' + x )
55- t . ok ( commentWithCharSet ( x , '' ) , 'matches ' + x + ' with charset' )
56- t . ok ( commentWithCharSet ( x , '' , '=' ) , 'matches ' + x + ' with charset' )
79+ t . ok ( comment ( x , '' ) , 'matches ' + x )
80+ t . ok ( commentWithCharSet ( x , '' ) , 'matches ' + x + ' with charset' )
81+ t . ok ( commentURI ( x , '' ) , 'matches ' + x + ' uri' )
82+ t . ok ( commentURIWithCharSet ( x , '' ) , 'matches ' + x + ' uri with charset' )
83+ t . ok ( commentWithoutMediaType ( x , '' ) , 'matches ' + x + ' without media type' )
84+ t . ok ( commentURIWithoutMediaType ( x , '' ) , 'matches ' + x + ' uri without media type' )
5785 } ) ;
5886
5987 [
6088 ' #// #' ,
6189 ' #/* #' ,
62- ] . forEach ( function ( x ) { t . ok ( ! comment ( x , '' ) , 'should not match ' + x ) } )
90+ ] . forEach ( function ( x ) {
91+ t . ok ( ! comment ( x , '' ) , 'should not match ' + x )
92+ t . ok ( ! commentURI ( x , '' ) , 'should not match ' + x + ' uri' )
93+ } )
94+
95+ t . end ( )
96+ } )
97+
98+ test ( 'comment regex groups' , function ( t ) {
99+ function comment ( prefix , suffix ) {
100+ var rx = convert . commentRegex ;
101+ return rx . exec ( prefix + 'sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiIiwic291cmNlcyI6WyJmdW5jdGlvbiBmb28oKSB7XG4gY29uc29sZS5sb2coXCJoZWxsbyBJIGFtIGZvb1wiKTtcbiBjb25zb2xlLmxvZyhcIndobyBhcmUgeW91XCIpO1xufVxuXG5mb28oKTtcbiJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSJ9' + suffix )
102+ }
103+
104+ function commentURI ( prefix , suffix ) {
105+ var rx = convert . commentRegex ;
106+ return rx . exec ( prefix + 'sourceMappingURL=data:application/json,%7B%22version%22%3A3%2C%22file%22%3A%22%22%2C%22sources%22%3A%5B%22function%20foo()%20%7B%0A%20console.log(%22hello%20I%20am%20foo%22)%3B%0A%20console.log(%22who%20are%20you%22)%3B%0A%7D%0A%0Afoo()%3B%0A%22%5D%2C%22names%22%3A%5B%5D%2C%22mappings%22%3A%22AAAA%22%7D' + suffix )
107+ }
108+
109+ function commentWithCharSet ( prefix , suffix ) {
110+ var rx = convert . commentRegex ;
111+ return rx . exec ( prefix + 'sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiIiwic291cmNlcyI6WyJmdW5jdGlvbiBmb28oKSB7XG4gY29uc29sZS5sb2coXCJoZWxsbyBJIGFtIGZvb1wiKTtcbiBjb25zb2xlLmxvZyhcIndobyBhcmUgeW91XCIpO1xufVxuXG5mb28oKTtcbiJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSJ9' + suffix )
112+ }
113+
114+ function commentURIWithCharSet ( prefix , suffix ) {
115+ var rx = convert . commentRegex ;
116+ return rx . exec ( prefix + 'sourceMappingURL=data:application/json;charset=utf-8,%7B%22version%22%3A3%2C%22file%22%3A%22%22%2C%22sources%22%3A%5B%22function%20foo()%20%7B%0A%20console.log(%22hello%20I%20am%20foo%22)%3B%0A%20console.log(%22who%20are%20you%22)%3B%0A%7D%0A%0Afoo()%3B%0A%22%5D%2C%22names%22%3A%5B%5D%2C%22mappings%22%3A%22AAAA%22%7D' + suffix )
117+ }
118+
119+ function commentWithoutMediaType ( prefix , suffix ) {
120+ var rx = convert . commentRegex ;
121+ return rx . exec ( prefix + 'sourceMappingURL=data:;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiIiwic291cmNlcyI6WyJmdW5jdGlvbiBmb28oKSB7XG4gY29uc29sZS5sb2coXCJoZWxsbyBJIGFtIGZvb1wiKTtcbiBjb25zb2xlLmxvZyhcIndobyBhcmUgeW91XCIpO1xufVxuXG5mb28oKTtcbiJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSJ9' + suffix )
122+ }
123+
124+ function commentURIWithoutMediaType ( prefix , suffix ) {
125+ var rx = convert . commentRegex ;
126+ return rx . exec ( prefix + 'sourceMappingURL=data:,%7B%22version%22%3A3%2C%22file%22%3A%22%22%2C%22sources%22%3A%5B%22function%20foo()%20%7B%0A%20console.log(%22hello%20I%20am%20foo%22)%3B%0A%20console.log(%22who%20are%20you%22)%3B%0A%7D%0A%0Afoo()%3B%0A%22%5D%2C%22names%22%3A%5B%5D%2C%22mappings%22%3A%22AAAA%22%7D' + suffix )
127+ }
128+
129+ [
130+ ' //# ' , // with leading spaces
131+ '\t//# ' , // with leading tab
132+ '//# ' , // with leading text
133+ '/*# ' , // multi line style
134+ ' /*# ' , // multi line style with leading spaces
135+ '\t/*# ' , // multi line style with leading tab
136+ '/*# ' , // multi line style with leading text
137+ ] . forEach ( function ( x ) {
138+ var m ;
139+ m = comment ( x , '' )
140+ t . ok ( m , 'matches ' + x )
141+ t . ok ( m [ 0 ] , 'comment' )
142+ t . equal ( m [ 1 ] , 'application/json' , 'media type' )
143+ t . equal ( m [ 2 ] , 'application/json' , 'MIME type' )
144+ t . equal ( m [ 3 ] , undefined , 'undefined charset' )
145+ t . equal ( m [ 4 ] , 'base64' , 'base64 encoding' )
146+ t . ok ( m [ 5 ] , 'data' )
147+ m = commentURI ( x , '' )
148+ t . ok ( m , 'matches ' + x + ' uri' )
149+ t . ok ( m [ 0 ] , 'comment uri' )
150+ t . equal ( m [ 1 ] , 'application/json' , 'media type uri' )
151+ t . equal ( m [ 2 ] , 'application/json' , 'MIME type uri' )
152+ t . equal ( m [ 3 ] , undefined , 'undefined charset uri' )
153+ t . equal ( m [ 4 ] , undefined , 'undefined encoding uri' )
154+ t . ok ( m [ 5 ] , 'data uri' )
155+ m = commentWithCharSet ( x , '' )
156+ t . ok ( m , 'matches ' + x + ' with charset' )
157+ t . ok ( m [ 0 ] , 'comment with charset' )
158+ t . equal ( m [ 1 ] , 'application/json;charset=utf-8' , 'media type with charset' )
159+ t . equal ( m [ 2 ] , 'application/json' , 'MIME type with charset' )
160+ t . equal ( m [ 3 ] , 'utf-8' , 'charset with utf-8' )
161+ t . equal ( m [ 4 ] , 'base64' , 'base64 encoding with charset' )
162+ t . ok ( m [ 5 ] , 'data with charset' )
163+ m = commentURIWithCharSet ( x , '' )
164+ t . ok ( m , 'matches ' + x + ' uri with charset' )
165+ t . ok ( m [ 0 ] , 'comment uri with charset' )
166+ t . equal ( m [ 1 ] , 'application/json;charset=utf-8' , 'media type uri with charset' )
167+ t . equal ( m [ 2 ] , 'application/json' , 'MIME type uri with charset' )
168+ t . equal ( m [ 3 ] , 'utf-8' , 'charset uri with utf-8' )
169+ t . equal ( m [ 4 ] , undefined , 'undefined encoding uri with charset' )
170+ t . ok ( m [ 5 ] , 'data with charset' )
171+ m = commentWithoutMediaType ( x , '' )
172+ t . ok ( m , 'matches ' + x + ' without media type' )
173+ t . ok ( m [ 0 ] , 'comment without media type' )
174+ t . equal ( m [ 1 ] , undefined , 'undefined media type' )
175+ t . equal ( m [ 2 ] , undefined , 'undefined MIME type' )
176+ t . equal ( m [ 3 ] , undefined , 'undefined charset without media type' )
177+ t . equal ( m [ 4 ] , 'base64' , 'base64 encoding without media type' )
178+ t . ok ( m [ 5 ] , 'data without media type' )
179+ m = commentURIWithoutMediaType ( x , '' )
180+ t . ok ( m , 'matches ' + x + ' uri without media type' )
181+ t . ok ( m [ 0 ] , 'comment uri without media type' )
182+ t . equal ( m [ 1 ] , undefined , 'undefined media type' )
183+ t . equal ( m [ 2 ] , undefined , 'undefined MIME type' )
184+ t . equal ( m [ 3 ] , undefined , 'undefined charset uri without media type' )
185+ t . equal ( m [ 4 ] , undefined , 'undefined encoding uri without media type' )
186+ t . ok ( m [ 5 ] , 'data uri without media type' )
187+ } ) ;
188+
189+ [
190+ ' #// #' ,
191+ ' #/* #' ,
192+ ] . forEach ( function ( x ) {
193+ t . ok ( ! comment ( x , '' ) , 'should not match ' + x )
194+ t . ok ( ! commentURI ( x , '' ) , 'should not match ' + x + ' uri' )
195+ } )
63196
64197 t . end ( )
65198} )
0 commit comments