@@ -24,8 +24,8 @@ var __extends = (this && this.__extends) || (function () {
24
24
} ) ( ) ;
25
25
Object . defineProperty ( exports , "__esModule" , { value : true } ) ;
26
26
var ipaddr = require ( "ipaddr.js" ) ;
27
- var js_base64_1 = require ( ' js-base64' ) ;
28
- var punycode = require ( "punycode" ) ;
27
+ var js_base64_1 = require ( " js-base64" ) ;
28
+ var punycode = require ( "punycode/ " ) ;
29
29
// Custom error base class
30
30
var ShadowsocksConfigError = /** @class */ ( function ( _super ) {
31
31
__extends ( ShadowsocksConfigError , _super ) ;
@@ -299,7 +299,7 @@ exports.LEGACY_BASE64_URI = {
299
299
var b64EncodedData = js_base64_1 . Base64 . encode ( data ) ;
300
300
// Remove "=" padding
301
301
while ( b64EncodedData . slice ( - 1 ) === '=' ) {
302
- b64EncodedData = b64EncodedData . slice ( 0 , - 1 ) ;
302
+ b64EncodedData = b64EncodedData . slice ( 0 , - 1 ) ;
303
303
}
304
304
return "ss://" + b64EncodedData + hash ;
305
305
} ,
@@ -367,34 +367,35 @@ exports.ONLINE_CONFIG_PROTOCOL = 'ssconf';
367
367
// Parses access parameters to retrieve a Shadowsocks proxy config from an
368
368
// online config URL. See: https://github.com/shadowsocks/shadowsocks-org/issues/89
369
369
function parseOnlineConfigUrl ( url ) {
370
- if ( ! url || ! url . startsWith ( exports . ONLINE_CONFIG_PROTOCOL + ':' ) ) {
371
- throw new InvalidUri ( 'URI protocol must be "' + exports . ONLINE_CONFIG_PROTOCOL + '"' ) ;
372
- }
373
- // Replace the protocol "ssconf" with "https" to ensure correct results,
374
- // otherwise some Safari versions fail to parse it.
375
- var inputForUrlParser = url . replace ( new RegExp ( '^' + exports . ONLINE_CONFIG_PROTOCOL ) , 'https' ) ;
376
- // The built-in URL parser throws as desired when given URIs with invalid syntax.
377
- var urlParserResult = new URL ( inputForUrlParser ) ;
378
- // Use ValidatedConfigFields subclasses (Host, Port, Tag) to throw on validation failure.
379
- var uriFormattedHost = urlParserResult . hostname ;
380
- var host ;
381
- try {
382
- host = new Host ( uriFormattedHost ) ;
383
- } catch ( _ ) {
384
- // Could be IPv6 host formatted with surrounding brackets, so try stripping first and last
385
- // characters. If this throws, give up and let the exception propagate.
386
- host = new Host ( uriFormattedHost . substring ( 1 , uriFormattedHost . length - 1 ) ) ;
387
- }
388
- // The default URL parser fails to recognize the default HTTPs port (443).
389
- var port = new Port ( urlParserResult . port || '443' ) ;
390
- // Parse extra parameters from the tag, which has the URL search parameters format.
391
- var tag = new Tag ( urlParserResult . hash . substring ( 1 ) ) ;
392
- var params = new URLSearchParams ( tag . data ) ;
393
- return {
394
- // Build the access URL with the parsed parameters Exclude the query string and tag.
395
- location : 'https://' + uriFormattedHost + ':' + port . data + urlParserResult . pathname ,
396
- certFingerprint : params . get ( 'certFp' ) || undefined ,
397
- httpMethod : params . get ( 'httpMethod' ) || undefined
398
- } ;
370
+ if ( ! url || ! url . startsWith ( exports . ONLINE_CONFIG_PROTOCOL + ":" ) ) {
371
+ throw new InvalidUri ( "URI protocol must be \"" + exports . ONLINE_CONFIG_PROTOCOL + "\"" ) ;
372
+ }
373
+ // Replace the protocol "ssconf" with "https" to ensure correct results,
374
+ // otherwise some Safari versions fail to parse it.
375
+ var inputForUrlParser = url . replace ( new RegExp ( "^" + exports . ONLINE_CONFIG_PROTOCOL ) , 'https' ) ;
376
+ // The built-in URL parser throws as desired when given URIs with invalid syntax.
377
+ var urlParserResult = new URL ( inputForUrlParser ) ;
378
+ // Use ValidatedConfigFields subclasses (Host, Port, Tag) to throw on validation failure.
379
+ var uriFormattedHost = urlParserResult . hostname ;
380
+ var host ;
381
+ try {
382
+ host = new Host ( uriFormattedHost ) ;
383
+ }
384
+ catch ( _ ) {
385
+ // Could be IPv6 host formatted with surrounding brackets, so try stripping first and last
386
+ // characters. If this throws, give up and let the exception propagate.
387
+ host = new Host ( uriFormattedHost . substring ( 1 , uriFormattedHost . length - 1 ) ) ;
388
+ }
389
+ // The default URL parser fails to recognize the default HTTPs port (443).
390
+ var port = new Port ( urlParserResult . port || '443' ) ;
391
+ // Parse extra parameters from the tag, which has the URL search parameters format.
392
+ var tag = new Tag ( urlParserResult . hash . substring ( 1 ) ) ;
393
+ var params = new URLSearchParams ( tag . data ) ;
394
+ return {
395
+ // Build the access URL with the parsed parameters Exclude the query string and tag.
396
+ location : "https://" + uriFormattedHost + ":" + port . data + urlParserResult . pathname ,
397
+ certFingerprint : params . get ( 'certFp' ) || undefined ,
398
+ httpMethod : params . get ( 'httpMethod' ) || undefined
399
+ } ;
399
400
}
400
401
exports . parseOnlineConfigUrl = parseOnlineConfigUrl ;
0 commit comments