@@ -47,6 +47,22 @@ export interface OracleFusionRequest {
4747 query ?: Record < string , string | number | boolean | undefined >
4848}
4949
50+ function compareDecimalMagnitudeToInteger ( magnitude : string , value : number ) : number {
51+ const normalizedMagnitude = magnitude . replace ( / ^ 0 + / , '' ) || '0'
52+ const integer = String ( value )
53+ if ( normalizedMagnitude . length !== integer . length ) {
54+ return normalizedMagnitude . length < integer . length ? - 1 : 1
55+ }
56+ if ( normalizedMagnitude === integer ) return 0
57+ return normalizedMagnitude < integer ? - 1 : 1
58+ }
59+
60+ function trailingZeroCount ( value : string ) : number {
61+ let count = 0
62+ for ( let index = value . length - 1 ; index >= 0 && value [ index ] === '0' ; index -- ) count ++
63+ return count
64+ }
65+
5066function validateBasicCredential ( accessToken : string ) : void {
5167 if (
5268 ! accessToken ||
@@ -105,16 +121,17 @@ function isIntegralJsonNumberToken(source: string): boolean {
105121
106122 const fractionDigits = match [ 2 ] ?. length ?? 0
107123 const exponentSource = match [ 3 ] ?? '0'
108- const exponentDigits = exponentSource . replace ( / ^ [ + - ] / , '' ) . replace ( / ^ 0 + / , '' ) || '0'
109- if ( exponentDigits . length > 6 ) return ! exponentSource . startsWith ( '-' )
110- const exponent = Number ( exponentSource )
111- const remainingFractionDigits = fractionDigits - exponent
112- if ( remainingFractionDigits <= 0 ) return true
113- if ( remainingFractionDigits > coefficient . length ) return false
114- return coefficient
115- . slice ( - remainingFractionDigits )
116- . split ( '' )
117- . every ( ( digit ) => digit === '0' )
124+ const exponentMagnitude = exponentSource . replace ( / ^ [ + - ] / , '' ) . replace ( / ^ 0 + / , '' ) || '0'
125+ const availableTrailingZeros = trailingZeroCount ( coefficient )
126+
127+ if ( exponentSource . startsWith ( '-' ) ) {
128+ if ( compareDecimalMagnitudeToInteger ( exponentMagnitude , availableTrailingZeros ) > 0 ) {
129+ return false
130+ }
131+ return fractionDigits + Number ( exponentMagnitude ) <= availableTrailingZeros
132+ }
133+ if ( compareDecimalMagnitudeToInteger ( exponentMagnitude , fractionDigits ) >= 0 ) return true
134+ return fractionDigits - Number ( exponentMagnitude ) <= availableTrailingZeros
118135}
119136
120137function parseOracleFusionJson ( body : string ) : unknown {
0 commit comments