Skip to content

Commit

Permalink
Change the type of 'uriComponent' (passed to 'encodeURIComponent') fr…
Browse files Browse the repository at this point in the history
…om 'string' to 'string | number | boolean'. Fixes #18159 (#31103)

- According to the ECMAScript 5.1 spec (§15.1.3.4), 'encodeURIComponent' invokes the abstract operation 'ToString': https://www.ecma-international.org/ecma-262/5.1/#sec-15.1.3.4
- In the spec (§9.8), 'ToString' accepts an 'Undefined', 'Null', 'Boolean', 'Number', 'String' or 'Object' argument: https://www.ecma-international.org/ecma-262/5.1/#sec-9.8
- TypeScript’s 'StringConstructor' accepts an argument with type 'any': https://github.com/Microsoft/TypeScript/blob/b0100100a18d740ad0b7c626bc81b800b5273ece/lib/lib.es5.d.ts#L518
  • Loading branch information
smockle authored and RyanCavanaugh committed Apr 26, 2019
1 parent 94ee0dc commit d934401
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/lib/es5.d.ts
Expand Up @@ -60,7 +60,7 @@ declare function encodeURI(uri: string): string;
* Encodes a text string as a valid component of a Uniform Resource Identifier (URI).
* @param uriComponent A value representing an encoded URI component.
*/
declare function encodeURIComponent(uriComponent: string): string;
declare function encodeURIComponent(uriComponent: string | number | boolean): string;

/**
* Computes a new string in which certain characters have been replaced by a hexadecimal escape sequence.
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/1.0lib-noErrors.js
Expand Up @@ -78,7 +78,7 @@ declare function encodeURI(uri: string): string;
* Encodes a text string as a valid component of a Uniform Resource Identifier (URI).
* @param uriComponent A value representing an encoded URI component.
*/
declare function encodeURIComponent(uriComponent: string): string;
declare function encodeURIComponent(uriComponent: string | number | boolean): string;

interface PropertyDescriptor {
configurable?: boolean;
Expand Down Expand Up @@ -1141,7 +1141,7 @@ declare var Array: {
<T>(...items: T[]): T[];
isArray(arg: any): boolean;
prototype: Array<any>;
}
}

//// [1.0lib-noErrors.js]
/* *****************************************************************************
Expand Down
11 changes: 6 additions & 5 deletions tests/baselines/reference/1.0lib-noErrors.symbols
Expand Up @@ -98,12 +98,12 @@ declare function encodeURI(uri: string): string;
* Encodes a text string as a valid component of a Uniform Resource Identifier (URI).
* @param uriComponent A value representing an encoded URI component.
*/
declare function encodeURIComponent(uriComponent: string): string;
declare function encodeURIComponent(uriComponent: string | number | boolean): string;
>encodeURIComponent : Symbol(encodeURIComponent, Decl(1.0lib-noErrors.ts, 73, 48))
>uriComponent : Symbol(uriComponent, Decl(1.0lib-noErrors.ts, 79, 36))

interface PropertyDescriptor {
>PropertyDescriptor : Symbol(PropertyDescriptor, Decl(1.0lib-noErrors.ts, 79, 66))
>PropertyDescriptor : Symbol(PropertyDescriptor, Decl(1.0lib-noErrors.ts, 79, 85))

configurable?: boolean;
>configurable : Symbol(PropertyDescriptor.configurable, Decl(1.0lib-noErrors.ts, 81, 30))
Expand All @@ -130,7 +130,7 @@ interface PropertyDescriptorMap {

[s: string]: PropertyDescriptor;
>s : Symbol(s, Decl(1.0lib-noErrors.ts, 91, 5))
>PropertyDescriptor : Symbol(PropertyDescriptor, Decl(1.0lib-noErrors.ts, 79, 66))
>PropertyDescriptor : Symbol(PropertyDescriptor, Decl(1.0lib-noErrors.ts, 79, 85))
}

interface Object {
Expand Down Expand Up @@ -217,7 +217,7 @@ declare var Object: {
>getOwnPropertyDescriptor : Symbol(getOwnPropertyDescriptor, Decl(1.0lib-noErrors.ts, 141, 32))
>o : Symbol(o, Decl(1.0lib-noErrors.ts, 149, 29))
>p : Symbol(p, Decl(1.0lib-noErrors.ts, 149, 36))
>PropertyDescriptor : Symbol(PropertyDescriptor, Decl(1.0lib-noErrors.ts, 79, 66))
>PropertyDescriptor : Symbol(PropertyDescriptor, Decl(1.0lib-noErrors.ts, 79, 85))

/**
* Returns the names of the own properties of an object. The own properties of an object are those that are defined directly
Expand Down Expand Up @@ -250,7 +250,7 @@ declare var Object: {
>o : Symbol(o, Decl(1.0lib-noErrors.ts, 171, 19))
>p : Symbol(p, Decl(1.0lib-noErrors.ts, 171, 26))
>attributes : Symbol(attributes, Decl(1.0lib-noErrors.ts, 171, 37))
>PropertyDescriptor : Symbol(PropertyDescriptor, Decl(1.0lib-noErrors.ts, 79, 66))
>PropertyDescriptor : Symbol(PropertyDescriptor, Decl(1.0lib-noErrors.ts, 79, 85))

/**
* Adds one or more properties to an object, and/or modifies attributes of existing properties.
Expand Down Expand Up @@ -2084,3 +2084,4 @@ declare var Array: {
>prototype : Symbol(prototype, Decl(1.0lib-noErrors.ts, 1140, 31))
>Array : Symbol(Array, Decl(1.0lib-noErrors.ts, 973, 23), Decl(1.0lib-noErrors.ts, 1133, 11))
}

7 changes: 4 additions & 3 deletions tests/baselines/reference/1.0lib-noErrors.types
Expand Up @@ -98,9 +98,9 @@ declare function encodeURI(uri: string): string;
* Encodes a text string as a valid component of a Uniform Resource Identifier (URI).
* @param uriComponent A value representing an encoded URI component.
*/
declare function encodeURIComponent(uriComponent: string): string;
>encodeURIComponent : (uriComponent: string) => string
>uriComponent : string
declare function encodeURIComponent(uriComponent: string | number | boolean): string;
>encodeURIComponent : (uriComponent: string | number | boolean) => string
>uriComponent : string | number | boolean

interface PropertyDescriptor {
configurable?: boolean;
Expand Down Expand Up @@ -1911,3 +1911,4 @@ declare var Array: {
prototype: Array<any>;
>prototype : any[]
}

2 changes: 1 addition & 1 deletion tests/baselines/reference/parserRegularExpression4.types
Expand Up @@ -61,7 +61,7 @@ if (Ca.test(c.href) || Ba.test(c.href) && /(\\?|&)adurl=/.test(c.href) && !/(\\?
>"&q=" + encodeURIComponent(W("q") || W("as_q") || A) : string
>"&q=" : "&q="
>encodeURIComponent(W("q") || W("as_q") || A) : string
>encodeURIComponent : (uriComponent: string) => string
>encodeURIComponent : (uriComponent: string | number | boolean) => string
>W("q") || W("as_q") || A : any
>W("q") || W("as_q") : any
>W("q") : any
Expand Down
4 changes: 2 additions & 2 deletions tests/cases/conformance/decorators/1.0lib-noErrors.ts
Expand Up @@ -78,7 +78,7 @@ declare function encodeURI(uri: string): string;
* Encodes a text string as a valid component of a Uniform Resource Identifier (URI).
* @param uriComponent A value representing an encoded URI component.
*/
declare function encodeURIComponent(uriComponent: string): string;
declare function encodeURIComponent(uriComponent: string | number | boolean): string;

interface PropertyDescriptor {
configurable?: boolean;
Expand Down Expand Up @@ -1141,4 +1141,4 @@ declare var Array: {
<T>(...items: T[]): T[];
isArray(arg: any): boolean;
prototype: Array<any>;
}
}
2 changes: 1 addition & 1 deletion tests/lib/lib.d.ts
Expand Up @@ -77,7 +77,7 @@ declare function encodeURI(uri: string): string;
* Encodes a text string as a valid component of a Uniform Resource Identifier (URI).
* @param uriComponent A value representing an encoded URI component.
*/
declare function encodeURIComponent(uriComponent: string): string;
declare function encodeURIComponent(uriComponent: string | number | boolean): string;

/**
* Computes a new string in which certain characters have been replaced by a hexadecimal escape sequence.
Expand Down

0 comments on commit d934401

Please sign in to comment.