@@ -280,7 +280,8 @@ export class DefaultUrlSerializer implements UrlSerializer {
280
280
serialize ( tree : UrlTree ) : string {
281
281
const segment = `/${ serializeSegment ( tree . root , true ) } ` ;
282
282
const query = serializeQueryParams ( tree . queryParams ) ;
283
- const fragment = typeof tree . fragment === `string` ? `#${ encodeUriQuery ( tree . fragment ! ) } ` : '' ;
283
+ const fragment =
284
+ typeof tree . fragment === `string` ? `#${ encodeUriFragment ( tree . fragment ! ) } ` : '' ;
284
285
285
286
return `${ segment } ${ query } ${ fragment } ` ;
286
287
}
@@ -329,13 +330,7 @@ function serializeSegment(segment: UrlSegmentGroup, root: boolean): string {
329
330
* Encodes a URI string with the default encoding. This function will only ever be called from
330
331
* `encodeUriQuery` or `encodeUriSegment` as it's the base set of encodings to be used. We need
331
332
* a custom encoding because encodeURIComponent is too aggressive and encodes stuff that doesn't
332
- * have to be encoded per http://tools.ietf.org/html/rfc3986:
333
- * query = *( pchar / "/" / "?" )
334
- * pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
335
- * unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
336
- * pct-encoded = "%" HEXDIG HEXDIG
337
- * sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
338
- * / "*" / "+" / "," / ";" / "="
333
+ * have to be encoded per https://url.spec.whatwg.org.
339
334
*/
340
335
function encodeUriString ( s : string ) : string {
341
336
return encodeURIComponent ( s )
@@ -346,15 +341,25 @@ function encodeUriString(s: string): string {
346
341
}
347
342
348
343
/**
349
- * This function should be used to encode both keys and values in a query string key/value or the
350
- * URL fragment. In the following URL, you need to call encodeUriQuery on "k", "v" and "f ":
344
+ * This function should be used to encode both keys and values in a query string key/value. In
345
+ * the following URL, you need to call encodeUriQuery on "k" and "v ":
351
346
*
352
347
* http://www.site.org/html;mk=mv?k=v#f
353
348
*/
354
349
export function encodeUriQuery ( s : string ) : string {
355
350
return encodeUriString ( s ) . replace ( / % 3 B / gi, ';' ) ;
356
351
}
357
352
353
+ /**
354
+ * This function should be used to encode a URL fragment. In the following URL, you need to call
355
+ * encodeUriFragment on "f":
356
+ *
357
+ * http://www.site.org/html;mk=mv?k=v#f
358
+ */
359
+ export function encodeUriFragment ( s : string ) : string {
360
+ return encodeURI ( s ) ;
361
+ }
362
+
358
363
/**
359
364
* This function should be run on any URI segment as well as the key and value in a key/value
360
365
* pair for matrix params. In the following URL, you need to call encodeUriSegment on "html",
0 commit comments