File tree Expand file tree Collapse file tree 3 files changed +54
-6
lines changed Expand file tree Collapse file tree 3 files changed +54
-6
lines changed Original file line number Diff line number Diff line change 71
71
"browser" : {
72
72
"binary-search" : false ,
73
73
"cheerio" : " jquery" ,
74
+ "url" : " ./src/url.js" ,
74
75
"./cli" : false ,
75
76
"./location" : false
76
77
},
Original file line number Diff line number Diff line change 8
8
/*eslint-env node */
9
9
10
10
var cheerio = require ( 'cheerio' ) ;
11
+ var parseUrl = require ( 'url' ) . parse ;
11
12
var semver = require ( 'semver' ) ;
12
13
var _location = require ( './location' ) ;
13
14
var LocationIndex = _location . LocationIndex ;
@@ -359,19 +360,27 @@ var LocationIndex = _location.LocationIndex;
359
360
360
361
// check for jQuery <script>s
361
362
var jqueries = $ ( [
362
- 'script[src*="jquery.min"]' ,
363
- 'script[src*="jQuery.min"]' ,
364
- 'script[src*="jquery.js"]' ,
365
- 'script[src*="jQuery.js"]'
363
+ 'script[src*="jquery"]' ,
364
+ 'script[src*="jQuery"]'
366
365
] . join ( ',' ) ) ;
367
366
if ( ! jqueries . length ) {
368
367
reporter ( NO_JQUERY ) ;
369
368
return ;
370
369
}
371
370
jqueries . each ( function ( ) {
372
371
var script = $ ( this ) ;
373
- var matches = script . attr ( 'src' ) . match ( / \d + \. \d + \. \d + / g) ;
374
- if ( ! matches ) {
372
+ var pathSegments = parseUrl ( script . attr ( 'src' ) ) . pathname . split ( '/' ) ;
373
+ var filename = pathSegments [ pathSegments . length - 1 ] ;
374
+ if ( ! / ^ j [ q Q ] u e r y ( \. m i n ) ? \. j s $ / . test ( filename ) ) {
375
+ return ;
376
+ }
377
+ var matches = pathSegments . map ( function ( segment ) {
378
+ var match = segment . match ( / ^ \d + \. \d + \. \d + $ / ) ;
379
+ return match ? match [ 0 ] : null ;
380
+ } ) . filter ( function ( match ) {
381
+ return match !== null ;
382
+ } ) ;
383
+ if ( ! matches . length ) {
375
384
return ;
376
385
}
377
386
var version = matches [ matches . length - 1 ] ;
Original file line number Diff line number Diff line change
1
+ /*eslint-env node, browser */
2
+ /* jshint browser: true */
3
+ /**
4
+ * Simple lightweight shim of Node.js's `url.parse()`
5
+ * ( http://nodejs.org/docs/latest/api/url.html )
6
+ * for use within browsers.
7
+ */
8
+ ( function ( ) {
9
+ 'use strict' ;
10
+
11
+ // Only properties common to both browsers and Node.js are supported.
12
+ // For what browsers support, see https://developer.mozilla.org/en-US/docs/Web/API/URLUtils
13
+ var URL_PROPERTIES = [
14
+ 'hash' ,
15
+ 'host' ,
16
+ 'hostname' ,
17
+ 'href' ,
18
+ 'pathname' ,
19
+ 'port' ,
20
+ 'protocol' ,
21
+ 'search'
22
+ ] ;
23
+
24
+ /**
25
+ * @param {string } urlStr URL to parse
26
+ * @returns {object } Object with fields representing the various parts of the parsed URL.
27
+ */
28
+ function parse ( urlStr ) {
29
+ var anchor = document . createElement ( 'a' ) ;
30
+ anchor . href = urlStr ;
31
+ var urlObj = { } ;
32
+ URL_PROPERTIES . forEach ( function ( property ) {
33
+ urlObj [ property ] = anchor [ property ] ;
34
+ } ) ;
35
+ return urlObj ;
36
+ }
37
+ exports . parse = parse ;
38
+ } ) ( ) ;
You can’t perform that action at this time.
0 commit comments