@@ -48,6 +48,50 @@ fakeRequest.log = function(msg) {
48
48
console . log ( msg ) ;
49
49
}
50
50
51
+ function testEncodeURIComponent ( ) {
52
+ printHeader ( 'testEncodeURIComponent' ) ;
53
+ function testPureAsciiAlphaNum ( ) {
54
+ console . log ( ' ## testPureAsciiAlphaNum' ) ;
55
+ let alphaNum = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789' ;
56
+ let encoded = s3gateway . _encodeURIComponent ( alphaNum ) ;
57
+ if ( alphaNum !== alphaNum ) {
58
+ throw 'Incorrect encoding applied to string.\n' +
59
+ `Actual: [${ encoded } ]\n` +
60
+ `Expected: [${ expected } ]` ;
61
+ }
62
+ }
63
+ function testUnicodeText ( ) {
64
+ console . log ( ' ## testUnicodeText' ) ;
65
+ let unicode = 'これは This is ASCII системы חן ' ;
66
+ let expected = '%E3%81%93%E3%82%8C%E3%81%AF%E3%80%80This%20is%20ASCII%20%D1%81%D0%B8%D1%81%D1%82%D0%B5%D0%BC%D1%8B%20%20%D7%97%D7%9F%20' ;
67
+ let encoded = s3gateway . _encodeURIComponent ( unicode ) ;
68
+ if ( expected !== encoded ) {
69
+ throw 'Incorrect encoding applied to string.\n' +
70
+ `Actual: [${ encoded } ]\n` +
71
+ `Expected: [${ expected } ]` ;
72
+ }
73
+ }
74
+ function testDiceyCharactersInText ( ) {
75
+ console . log ( ' ## testDiceyCharactersInText' ) ;
76
+
77
+ let diceyCharacters = '%@!*()=+$#^&|\\/' ;
78
+ for ( let i = 0 ; i < diceyCharacters . length ; i ++ ) {
79
+ let char = diceyCharacters [ i ] ;
80
+ let encoded = s3gateway . _encodeURIComponent ( char ) ;
81
+ let expected = `%${ char . charCodeAt ( 0 ) . toString ( 16 ) . toUpperCase ( ) } ` ;
82
+ if ( encoded !== expected ) {
83
+ throw 'Incorrect encoding applied to string.\n' +
84
+ `Actual: [${ encoded } ]\n` +
85
+ `Expected: [${ expected } ]` ;
86
+ }
87
+ }
88
+ }
89
+
90
+ testPureAsciiAlphaNum ( ) ;
91
+ testUnicodeText ( ) ;
92
+ testDiceyCharactersInText ( ) ;
93
+ }
94
+
51
95
function testPad ( ) {
52
96
printHeader ( 'testPad' ) ;
53
97
var padSingleDigit = s3gateway . _padWithLeadingZeros ( 3 , 2 ) ;
@@ -568,6 +612,7 @@ function printHeader(testName) {
568
612
}
569
613
570
614
async function test ( ) {
615
+ testEncodeURIComponent ( ) ;
571
616
testPad ( ) ;
572
617
testEightDigitDate ( ) ;
573
618
testAmzDatetime ( ) ;
0 commit comments