From d934401265403de077bdf4782c967c0832874003 Mon Sep 17 00:00:00 2001 From: Clay Miller Date: Fri, 26 Apr 2019 13:07:14 -0700 Subject: [PATCH] Change the type of 'uriComponent' (passed to 'encodeURIComponent') from 'string' to 'string | number | boolean'. Fixes #18159 (#31103) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 --- src/lib/es5.d.ts | 2 +- tests/baselines/reference/1.0lib-noErrors.js | 4 ++-- tests/baselines/reference/1.0lib-noErrors.symbols | 11 ++++++----- tests/baselines/reference/1.0lib-noErrors.types | 7 ++++--- .../reference/parserRegularExpression4.types | 2 +- tests/cases/conformance/decorators/1.0lib-noErrors.ts | 4 ++-- tests/lib/lib.d.ts | 2 +- 7 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/lib/es5.d.ts b/src/lib/es5.d.ts index 994fb1d765330..d39613e515194 100644 --- a/src/lib/es5.d.ts +++ b/src/lib/es5.d.ts @@ -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. diff --git a/tests/baselines/reference/1.0lib-noErrors.js b/tests/baselines/reference/1.0lib-noErrors.js index ade0f4bf903b9..3dac98d9e5647 100644 --- a/tests/baselines/reference/1.0lib-noErrors.js +++ b/tests/baselines/reference/1.0lib-noErrors.js @@ -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; @@ -1141,7 +1141,7 @@ declare var Array: { (...items: T[]): T[]; isArray(arg: any): boolean; prototype: Array; -} +} //// [1.0lib-noErrors.js] /* ***************************************************************************** diff --git a/tests/baselines/reference/1.0lib-noErrors.symbols b/tests/baselines/reference/1.0lib-noErrors.symbols index adedbdb9aa2dc..d67952e201c98 100644 --- a/tests/baselines/reference/1.0lib-noErrors.symbols +++ b/tests/baselines/reference/1.0lib-noErrors.symbols @@ -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)) @@ -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 { @@ -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 @@ -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. @@ -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)) } + diff --git a/tests/baselines/reference/1.0lib-noErrors.types b/tests/baselines/reference/1.0lib-noErrors.types index 1d9c67834e702..91e5fdc7b7356 100644 --- a/tests/baselines/reference/1.0lib-noErrors.types +++ b/tests/baselines/reference/1.0lib-noErrors.types @@ -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; @@ -1911,3 +1911,4 @@ declare var Array: { prototype: Array; >prototype : any[] } + diff --git a/tests/baselines/reference/parserRegularExpression4.types b/tests/baselines/reference/parserRegularExpression4.types index 1a0db05a48e48..1af56c7a24fc6 100644 --- a/tests/baselines/reference/parserRegularExpression4.types +++ b/tests/baselines/reference/parserRegularExpression4.types @@ -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 diff --git a/tests/cases/conformance/decorators/1.0lib-noErrors.ts b/tests/cases/conformance/decorators/1.0lib-noErrors.ts index 6966e3e70d07d..391c0926a82b7 100644 --- a/tests/cases/conformance/decorators/1.0lib-noErrors.ts +++ b/tests/cases/conformance/decorators/1.0lib-noErrors.ts @@ -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; @@ -1141,4 +1141,4 @@ declare var Array: { (...items: T[]): T[]; isArray(arg: any): boolean; prototype: Array; -} \ No newline at end of file +} \ No newline at end of file diff --git a/tests/lib/lib.d.ts b/tests/lib/lib.d.ts index ad17bec673e95..5f089bb3c82eb 100644 --- a/tests/lib/lib.d.ts +++ b/tests/lib/lib.d.ts @@ -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.