@@ -18,6 +18,19 @@ const rules = {
1818
1919/* eslint-enable no-control-regex */
2020
21+ /**
22+ * Ensure the value is a string.
23+ * @private
24+ * @param s {any} the value to be checked
25+ * @throws {TypeError } if the value is not a string
26+ */
27+ const assertString = ( s ) => {
28+ const t = typeof s ;
29+ if ( t !== 'string' ) {
30+ throw new TypeError ( 'Value must be a string' ) ;
31+ }
32+ } ;
33+
2134/**
2235 * Minimal, RFC 6749, compliant unicode validator.
2336 * @see https://datatracker.ietf.org/doc/html/rfc6749#appendix-A
@@ -33,6 +46,7 @@ const isFormat = {
3346 */
3447
3548 nchar : function ( value ) {
49+ assertString ( value ) ;
3650 return rules . NCHAR . test ( value ) ;
3751 } ,
3852
@@ -45,6 +59,7 @@ const isFormat = {
4559 */
4660
4761 nqchar : function ( value ) {
62+ assertString ( value ) ;
4863 return rules . NQCHAR . test ( value ) ;
4964 } ,
5065
@@ -57,6 +72,7 @@ const isFormat = {
5772 */
5873
5974 nqschar : function ( value ) {
75+ assertString ( value ) ;
6076 return rules . NQSCHAR . test ( value ) ;
6177 } ,
6278
@@ -70,6 +86,7 @@ const isFormat = {
7086 */
7187
7288 uchar : function ( value ) {
89+ assertString ( value ) ;
7390 // manually test \u10000-\u10FFFF
7491 if ( rules . UNICODECHARNOCRLF . test ( value ) ) {
7592 return true ;
@@ -86,6 +103,7 @@ const isFormat = {
86103 * @return {boolean } true, if valid, otherwise false
87104 */
88105 uri : function ( value ) {
106+ assertString ( value ) ;
89107 return rules . URI . test ( value ) ;
90108 } ,
91109
@@ -98,6 +116,7 @@ const isFormat = {
98116 */
99117
100118 vschar : function ( value ) {
119+ assertString ( value ) ;
101120 return rules . VSCHAR . test ( value ) ;
102121 }
103122} ;
0 commit comments