@@ -29,7 +29,7 @@ namespace Js
29
29
}
30
30
}
31
31
32
- return Encode (strURI-> GetString (), strURI-> GetLength () , flags, scriptContext);
32
+ return Encode (strURI, flags, scriptContext);
33
33
}
34
34
35
35
unsigned char UriHelper::s_uriProps[128 ] =
@@ -126,10 +126,13 @@ namespace Js
126
126
}
127
127
128
128
// The Encode algorithm described in sec. 15.1.3 of the spec. The input string is
129
- // 'input ' and the Unescaped set is described by the flags 'unescapedFlags'. The
129
+ // 'strURI ' and the Unescaped set is described by the flags 'unescapedFlags'. The
130
130
// output is a string var.
131
- Var UriHelper::Encode (__in_ecount(len) const char16* input, uint32 len , unsigned char unescapedFlags, ScriptContext* scriptContext )
131
+ Var UriHelper::Encode (JavascriptString* strURI , unsigned char unescapedFlags, ScriptContext* scriptContext )
132
132
{
133
+ charcount_t len = strURI->GetLength ();
134
+ __in_ecount (len) const char16* input = strURI->GetString ();
135
+ bool needsChanges = false ;
133
136
BYTE bUTF8[MaxUTF8Len];
134
137
135
138
// pass 1 calculate output length and error check
@@ -144,6 +147,8 @@ namespace Js
144
147
}
145
148
else
146
149
{
150
+ needsChanges = true ;
151
+
147
152
if ( c >= 0xDC00 && c <= 0xDFFF )
148
153
{
149
154
JavascriptError::ThrowURIError (scriptContext, JSERR_URIEncodeError /* TODO-ERROR: _u("NEED MESSAGE") */ );
@@ -173,6 +178,13 @@ namespace Js
173
178
}
174
179
}
175
180
181
+ // If nothing needs encoding, then avoid extra work
182
+ if (!needsChanges)
183
+ {
184
+ AssertMsg (scriptContext == strURI->GetScriptContext (), " Should have already marshaled the string in cross site thunk" );
185
+ return strURI;
186
+ }
187
+
176
188
// pass 2 generate the encoded URI
177
189
178
190
uint32 allocSize = UInt32Math::Add (outputLen, 1 );
@@ -238,7 +250,7 @@ namespace Js
238
250
__analysis_assume (outputLen + 1 == allocSize);
239
251
outURI[outputLen] = _u (' \0 ' );
240
252
241
- return JavascriptString::NewCopyBuffer (outURI, outputLen, scriptContext);
253
+ return JavascriptString::NewWithBuffer (outURI, outputLen, scriptContext);
242
254
}
243
255
244
256
Var UriHelper::DecodeCoreURI (ScriptContext* scriptContext, Arguments& args, unsigned char reservedFlags )
@@ -265,14 +277,17 @@ namespace Js
265
277
}
266
278
}
267
279
268
- return Decode (strURI-> GetString (), strURI-> GetLength () , reservedFlags, scriptContext);
280
+ return Decode (strURI, reservedFlags, scriptContext);
269
281
}
270
282
271
283
// The Decode algorithm described in sec. 15.1.3 of the spec. The input string is
272
- // 'input ' and the Reserved set is described by the flags 'reservedFlags'. The
284
+ // 'strURI ' and the Reserved set is described by the flags 'reservedFlags'. The
273
285
// output is a string var.
274
- Var UriHelper::Decode (__in_ecount(len) const char16* input, uint32 len , unsigned char reservedFlags, ScriptContext* scriptContext)
286
+ Var UriHelper::Decode (JavascriptString* strURI , unsigned char reservedFlags, ScriptContext* scriptContext)
275
287
{
288
+ charcount_t len = strURI->GetLength ();
289
+ __in_ecount (len) const char16* input = strURI->GetString ();
290
+ bool needsChanges = false ;
276
291
char16 c1;
277
292
char16 c;
278
293
// pass 1 calculate output length and error check
@@ -283,6 +298,8 @@ namespace Js
283
298
284
299
if ( c == ' %' )
285
300
{
301
+ needsChanges = true ;
302
+
286
303
uint32 start = k;
287
304
if ( k + 2 >= len )
288
305
{
@@ -383,6 +400,13 @@ namespace Js
383
400
}
384
401
}
385
402
403
+ // If nothing needs decoding, then avoid extra work
404
+ if (!needsChanges)
405
+ {
406
+ AssertMsg (scriptContext == strURI->GetScriptContext (), " Should have already marshaled the string in cross site thunk" );
407
+ return strURI;
408
+ }
409
+
386
410
// pass 2 generate the decoded URI
387
411
uint32 allocSize = UInt32Math::Add (outputLen, 1 );
388
412
char16* outURI = RecyclerNewArrayLeaf (scriptContext->GetRecycler (), char16, allocSize);
@@ -538,7 +562,7 @@ namespace Js
538
562
__analysis_assume (outputLen + 1 == allocSize);
539
563
outURI[outputLen] = _u (' \0 ' );
540
564
541
- return JavascriptString::NewCopyBuffer (outURI, outputLen, scriptContext);
565
+ return JavascriptString::NewWithBuffer (outURI, outputLen, scriptContext);
542
566
}
543
567
544
568
// Decodes a two-hexadecimal-digit wide character pair into the byte value it represents
0 commit comments