jaxon-php / jaxon-core

The Jaxon core library
https://www.jaxon-php.org
BSD 3-Clause "New" or "Revised" License
65 stars 28 forks source link

Bug: Jaxon nullish coalescing operator ?? in ios safari mobile < v13 throws error #100

Closed simplexx closed 2 years ago

simplexx commented 2 years ago

PROBLEM

During testing, we have discovered a bug which affects all safari mobile versions < v13. The bug is related to the use of the nullish coalescing operator (??), which somehow does not work correctly in the current jaxon lib in these safari versions. We have verified this issue on browserstack.com on multiple different real devices using ios < v13, as well as on 1 device at hand. The error thrown in the console on the affected ios devices is the following:

jaxon.core.min.js:1 SyntaxError: Unexpected token '?'(anonymous function) @ jaxon.core.min.js:1 VM54 en:4356 TypeError: undefined is not an object (evaluating 'jaxon.dom.ready')

Which then leads to subsequential calls to jaxon failing like this:

jQuery.Deferred exception: jaxon.request is not a function. (In 'jaxon.request( { jxnfun: 'getBanners' }, { parameters: arguments } )', 'jaxon.request' is undefined) xajax_getBanners

TypeError: jaxon.request is not a function. (In 'jaxon.request( { jxnfun: 'getBanners' }, { parameters: arguments } )', 'jaxon.request' is undefined)

SOLUTION / FIX

We have implemented a temporary fix in the file jaxon.core.js, which seems to fix the problem, basically ?? changed to ? : -> But There might be a more elegant fix, we have not deeply investigated this, but this does fix the problem.

file jaxon.core.js line 2807: Old code: oValues[sBag] = jaxon.ajax.parameters.bags[sBag] ?? ''; New Code: oValues[sBag] = jaxon.ajax.parameters.bags[sBag] ? jaxon.ajax.parameters.bags[sBag] : '';

line 2842: Old code: oValues[sBag] = jaxon.ajax.parameters.bags[sBag] ?? ''; New Code: oValues[sBag] = jaxon.ajax.parameters.bags[sBag] ? jaxon.ajax.parameters.bags[sBag] : '';

line 3208: Old code: const oRequest = functionArgs ?? {}; New Code: const oRequest = functionArgs ? functionArgs : {};

Hopefully that helps, and thanks again for this great project!

-Chris

feuzeu commented 2 years ago

Hi,

I've made the change in the js package. Here the new tag: https://github.com/jaxon-php/jaxon-js/releases/tag/v3.3.2.

simplexx commented 2 years ago

Hi,

Awesome, thanks a lot!

-Chris

feuzeu commented 2 years ago

Thanks for reporting this issue.