@@ -1011,27 +1011,10 @@ export class RokuDeploy {
10111011 } as Record < string , any > ;
10121012
10131013 if ( options . enhance ) {
1014- // convert 'true' and 'false' string values to boolean
1015- for ( let key in deviceInfo ) {
1016- if ( deviceInfo [ key ] === 'true' ) {
1017- deviceInfo [ key ] = true ;
1018- } else if ( deviceInfo [ key ] === 'false' ) {
1019- deviceInfo [ key ] = false ;
1020- }
1021- }
1022-
1023- // convert the following string values into numbers
1024- const numberFields = [ 'software-build' , 'uptime' , 'trc-version' , 'av-sync-calibration-enabled' , 'time-zone-offset' ] ;
1025- for ( const field of numberFields ) {
1026- if ( deviceInfo . hasOwnProperty ( field ) ) {
1027- deviceInfo [ field ] = parseInt ( deviceInfo [ field ] ) ;
1028- }
1029- }
1030-
1031- //convert the property names to camel case
10321014 const result = { } ;
1033- for ( const key in deviceInfo ) {
1034- result [ lodash . camelCase ( key ) ] = deviceInfo [ key ] ;
1015+ // sanitize/normalize values to their native formats, and also convert property names to camelCase
1016+ for ( let key in deviceInfo ) {
1017+ result [ lodash . camelCase ( key ) ] = this . normalizeDeviceInfoFieldValue ( deviceInfo [ key ] ) ;
10351018 }
10361019 deviceInfo = result ;
10371020 }
@@ -1041,6 +1024,25 @@ export class RokuDeploy {
10411024 }
10421025 }
10431026
1027+ /**
1028+ * Normalize a deviceInfo field value. This includes things like converting boolean strings to booleans, number strings to numbers,
1029+ * decoding HtmlEntities, etc.
1030+ * @param deviceInfo
1031+ */
1032+ public normalizeDeviceInfoFieldValue ( value : any ) {
1033+ let num : number ;
1034+ // convert 'true' and 'false' string values to boolean
1035+ if ( value === 'true' ) {
1036+ return true ;
1037+ } else if ( value === 'false' ) {
1038+ return false ;
1039+ } else if ( value . trim ( ) !== '' && ! isNaN ( num = Number ( value ) ) ) {
1040+ return num ;
1041+ } else {
1042+ return util . decodeHtmlEntities ( value ) ;
1043+ }
1044+ }
1045+
10441046 public async getDevId ( options ?: RokuDeployOptions ) {
10451047 const deviceInfo = await this . getDeviceInfo ( options as any ) ;
10461048 return deviceInfo [ 'keyed-developer-id' ] ;
0 commit comments