mathiasbynens / punycode.js

A robust Punycode converter that fully complies to RFC 3492 and RFC 5891.
https://mths.be/punycode
MIT License
1.6k stars 159 forks source link

SyntaxError: Invalid character: '\0' #100

Closed mikoSTAR closed 1 year ago

mikoSTAR commented 4 years ago

Hi,

We use razzle and react for our project and it seems one of our libraries use punycode.js as it's dependency. We track our errors using Sentry.

We came across this error:

SyntaxError
Invalid character: '\0'

on device and browser:

browser
Mobile Safari UI/WKWebView 13.3.1
iPhone
os
iOS 13.3.1

which leads us to this code:

/***/ }),

/***/ "./node_modules/core-js/internals/punycode-to-ascii.js":
/*!*************************************************************!*\
  !*** ./node_modules/core-js/internals/punycode-to-ascii.js ***!
  \*************************************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {

"use strict";

// based on https://github.com/bestiejs/punycode.js/blob/master/punycode.js
var maxInt = 2147483647; // aka. 0x7FFFFFFF or 2^31-1
var base = 36;
var tMin = 1;
var tMax = 26;
var skew = 38;
var damp = 700;
var initialBias = 72;
var initialN = 128; // 0x80
var delimiter = '-'; // '\x2D'
var regexNonASCII = /[^\0-\u007E]/; // non-ASCII chars
var regexSeparators = /[.\u3002\uFF0E\uFF61]/g; // RFC 3490 separators
var OVERFLOW_ERROR = 'Overflow: input needs wider integers to process';

seems like this line is causing a problem: var regexNonASCII = /[^\0-\u007E]/; // non-ASCII chars

any clues on that?

cheers,

mathiasbynens commented 4 years ago

\0 is a valid escape sequence for U+0000 within string literals, template literals, and regular expression literals. Which JS engine are you seeing this issue in?

mikoSTAR commented 4 years ago

Hey thank you for quick reply. Issue appears on this kind of devices and browsers.

browser
Mobile Safari UI/WKWebView 13.3.1
iPhone
os
iOS 13.3.1

or

browser
Mobile Safari UI/WKWebView 12.4.4
device
iPhone
iOS 12.4.4

I was not able to fine exact JS engine but had a research and it looks like WKWebView stands for https://developer.apple.com/documentation/webkit/wkwebview

so it looks like it is some iOS app which use that WKWebView browser to display a content and that browser reacts different than standard Safari browser.

Let me know if it is useful

mathiasbynens commented 1 year ago

Is this still an issue in practice? This is clearly a browser bug which hopefully has been resolved by now. I’ll close this issue for now but please post if you have any updates.