1
1
'use strict' ;
2
2
3
3
var path = require ( 'path' ) ,
4
- fs = require ( 'fs' ) ,
5
- Q = require ( 'q' ) ,
6
- url = require ( 'url' ) ;
4
+ fs = require ( 'fs' ) ,
5
+ Q = require ( 'q' ) ,
6
+ url = require ( 'url' ) ;
7
7
8
8
var constants = require ( '../constants' ) ,
9
- log = require ( '../log' ) ,
10
- platformTools = require ( '../platformTools' ) ,
11
- utils = require ( '../utils' ) ;
9
+ log = require ( '../log' ) ,
10
+ platformTools = require ( '../platformTools' ) ,
11
+ utils = require ( '../utils' ) ;
12
12
13
13
var toStringFunction = Object . prototype . toString ;
14
14
15
15
// load the rule(s) from a folder or file
16
16
function loadValidationRules ( fileOrDir , platforms , callback ) {
17
17
18
- var stat = Q . nfbind ( fs . stat ) ;
18
+ var stat = Q . nfbind ( fs . stat ) ;
19
19
20
20
// list contents of the validation rules folder
21
21
return Q . nfcall ( fs . readdir , fileOrDir ) . then ( function ( files ) {
@@ -26,13 +26,13 @@ function loadValidationRules(fileOrDir, platforms, callback) {
26
26
if ( info . isDirectory ( ) ) {
27
27
// ignore any directory that doesn't match one of the requested platforms
28
28
if ( platforms . indexOf ( file ) < 0 ) {
29
- return Q . resolve ( ) ;
29
+ return Q . resolve ( ) ;
30
30
}
31
-
31
+
32
32
// process the rules in the platform folder
33
33
return loadValidationRules ( filePath , [ ] ) ;
34
34
}
35
-
35
+
36
36
// load the rules defined in the file
37
37
var rulePath = path . join ( fileOrDir , file ) ;
38
38
try {
@@ -44,40 +44,40 @@ function loadValidationRules(fileOrDir, platforms, callback) {
44
44
}
45
45
} ) ;
46
46
} ) )
47
- . then ( function ( results ) {
48
- // verify the results and consolidate the loaded rules
49
- return results . reduce ( function ( validationRules , result ) {
50
- if ( result . state === 'fulfilled' ) {
51
- if ( result . value ) {
52
- if ( Array . isArray ( result . value ) ) {
53
- validationRules . push . apply ( validationRules , result . value ) ;
47
+ . then ( function ( results ) {
48
+ // verify the results and consolidate the loaded rules
49
+ return results . reduce ( function ( validationRules , result ) {
50
+ if ( result . state === 'fulfilled' ) {
51
+ if ( result . value ) {
52
+ if ( Array . isArray ( result . value ) ) {
53
+ validationRules . push . apply ( validationRules , result . value ) ;
54
+ }
55
+ else {
56
+ validationRules . push ( result . value ) ;
57
+ }
54
58
}
55
- else {
56
- validationRules . push ( result . value ) ;
57
- }
58
- }
59
- }
60
- else {
61
- log . error ( result . reason . getMessage ( ) ) ;
62
- }
63
-
64
- return validationRules ;
65
- } , [ ] ) ;
66
- } ) ;
67
- } )
68
- . catch ( function ( err ) {
69
- if ( err . code !== 'ENOTDIR' ) {
70
- throw err ;
71
- }
72
-
73
- // fileOrDir is a file
74
- var rules = require ( fileOrDir ) ;
75
- return Array . isArray ( rules ) ? rules : [ rules ] ;
76
- } )
77
- . catch ( function ( err ) {
78
- return Q . reject ( new Error ( 'Failed to read validation rules from the specified location: \'' + fileOrDir + '\'. ' + err . message + '.' ) ) ;
59
+ }
60
+ else {
61
+ log . error ( result . reason . getMessage ( ) ) ;
62
+ }
63
+
64
+ return validationRules ;
65
+ } , [ ] ) ;
66
+ } ) ;
79
67
} )
80
- . nodeify ( callback ) ;
68
+ . catch ( function ( err ) {
69
+ if ( err . code !== 'ENOTDIR' ) {
70
+ throw err ;
71
+ }
72
+
73
+ // fileOrDir is a file
74
+ var rules = require ( fileOrDir ) ;
75
+ return Array . isArray ( rules ) ? rules : [ rules ] ;
76
+ } )
77
+ . catch ( function ( err ) {
78
+ return Q . reject ( new Error ( 'Failed to read validation rules from the specified location: \'' + fileOrDir + '\'. ' + err . message + '.' ) ) ;
79
+ } )
80
+ . nodeify ( callback ) ;
81
81
}
82
82
83
83
function runValidationRules ( w3cManifestInfo , rules , callback ) {
@@ -135,7 +135,7 @@ function applyValidationRules(w3cManifestInfo, platformModules, platforms) {
135
135
136
136
return Q . allSettled ( platformTasks ) ;
137
137
}
138
-
138
+
139
139
// Only run the "All Platform" validations for W3C manifests
140
140
if ( w3cManifestInfo . format === constants . BASE_MANIFEST_FORMAT ) {
141
141
return validateAllPlatforms ( )
@@ -160,12 +160,12 @@ function validateManifest(w3cManifestInfo, platforms, callback) {
160
160
return platformTools . loadPlatforms ( platforms ) . then ( function ( platformModules ) {
161
161
return applyValidationRules ( w3cManifestInfo , platformModules , platforms ) ;
162
162
} )
163
- . nodeify ( callback ) ;
163
+ . nodeify ( callback ) ;
164
164
}
165
165
166
166
function imageValidation ( manifestContent , description , platform , level , requiredIconSizes , callback ) {
167
167
var icons = manifestContent . icons ;
168
-
168
+
169
169
var result = {
170
170
description : description ,
171
171
platform : platform ,
@@ -208,7 +208,7 @@ function imageValidation(manifestContent, description, platform, level, required
208
208
209
209
function imageGroupValidation ( manifestContent , description , platform , validIconSizes , callback ) {
210
210
var icons = manifestContent . icons ;
211
-
211
+
212
212
var result = {
213
213
description : description ,
214
214
platform : platform ,
@@ -239,38 +239,43 @@ function validateAndNormalizeStartUrl(siteUrl, manifestInfo, callback) {
239
239
if ( manifestInfo . format !== constants . BASE_MANIFEST_FORMAT ) {
240
240
return callback ( new Error ( 'The manifest found is not a W3C manifest.' ) , manifestInfo ) ;
241
241
}
242
-
242
+
243
243
if ( manifestInfo . content . start_url ) {
244
244
if ( ! utils . isURL ( manifestInfo . content . start_url ) ) {
245
245
return callback ( new Error ( 'The manifest\'s start_url member is not a valid URL: \'' + manifestInfo . content . start_url + '\'' ) , manifestInfo ) ;
246
246
}
247
247
} else {
248
248
manifestInfo . content . start_url = '/' ;
249
249
}
250
-
250
+
251
251
if ( siteUrl ) {
252
252
if ( ! utils . isURL ( siteUrl ) ) {
253
253
return callback ( new Error ( 'The site URL is not a valid URL: \'' + siteUrl + '\'' ) , manifestInfo ) ;
254
254
}
255
-
255
+
256
256
var parsedSiteUrl = url . parse ( siteUrl ) ;
257
257
var parsedManifestStartUrl = url . parse ( manifestInfo . content . start_url ) ;
258
258
if ( parsedManifestStartUrl . hostname && parsedSiteUrl . hostname !== parsedManifestStartUrl . hostname ) {
259
- // issue #88 - bis
259
+ // issue #88 - bis
260
260
var subDomainOfManifestStartUrlSplitted = parsedManifestStartUrl . hostname . split ( '.' ) ;
261
261
var lengthSubDomain = subDomainOfManifestStartUrlSplitted . length ;
262
262
var subDomainOfManifestStartUrl = null ;
263
- if ( lengthSubDomain >= 2 ) {
264
- subDomainOfManifestStartUrl =
265
- subDomainOfManifestStartUrlSplitted [ lengthSubDomain - 2 ] + '.' + subDomainOfManifestStartUrlSplitted [ lengthSubDomain - 1 ] ;
263
+ if ( lengthSubDomain >= 2 ) {
264
+ subDomainOfManifestStartUrl =
265
+ subDomainOfManifestStartUrlSplitted [ lengthSubDomain - 2 ] + '.' + subDomainOfManifestStartUrlSplitted [ lengthSubDomain - 1 ] ;
266
266
}
267
- if ( ! subDomainOfManifestStartUrl || ! utils . isURL ( subDomainOfManifestStartUrl ) || parsedSiteUrl . hostname . toLowerCase ( ) !== subDomainOfManifestStartUrl . toLowerCase ( ) ) {
267
+ if ( ! subDomainOfManifestStartUrl || ! utils . isURL ( subDomainOfManifestStartUrl ) || parsedSiteUrl . hostname . toLowerCase ( ) !== subDomainOfManifestStartUrl . toLowerCase ( ) ) {
268
268
return callback ( new Error ( 'The domain of the hosted site (' + parsedSiteUrl . hostname + ') does not match the domain of the manifest\'s start_url member (' + parsedManifestStartUrl . hostname + ')' ) , manifestInfo ) ;
269
269
}
270
270
}
271
-
272
- manifestInfo . content . start_url = url . resolve ( siteUrl , manifestInfo . content . start_url ) ;
273
-
271
+
272
+ if ( parsedManifestStartUrl . search !== null ) {
273
+ manifestInfo . content . start_url = siteUrl . split ( '?' ) [ 0 ] ;
274
+ }
275
+ else {
276
+ manifestInfo . content . start_url = url . resolve ( siteUrl , manifestInfo . content . start_url ) ;
277
+ }
278
+
274
279
manifestInfo . default = { short_name : utils . getDefaultShortName ( siteUrl ) } ;
275
280
}
276
281
0 commit comments