JavaScript toLocaleTimeString() 在最新版本的 Chrome 中返回 ASCII 226 而不是空格。

huangapple go评论71阅读模式
英文:

Javascript toLocaleTimeString() Returning ASCII 226 Instead of Space in Latest Version of Chrome

问题

We use the Javascript function toLocaleTimeString() to parse date/times. The newest version of Chrome is returning an ASCII 226 between the seconds and the AM/PM part of the time suddenly. Edge is not having any issues nor are older versions of Chrome. 110+ has the issue and 109 or earlier does not.

For example, if the last couple of characters returned are:

00 AM

The ASCII translation of that is:

48 48 226 128 175

That 226 used to be a 32 (space).

Anyone else seeing this behavior as well?

英文:

We use the Javascript function toLocaleTimeString() to parse date/times. The newest version of Chrome is returning an ASCII 226 between the seconds and the AM/PM part of the time suddenly. Edge is not having any issues nor are older versions of Chrome. 110+ has the issue and 109 or earlier does not.

For example, if the last couple of characters returned are:

00 AM

The ASCII translation of that is:

48 48 226 128 175

That 226 used to be a 32 (space).

Anyone else seeing this behavior as well?

答案1

得分: 7

这明显是由于这个V8 CL引起的。

这是ChangeLog的摘要:

[intl] 增强日期解析器以接受Unicode空格

这是为了为ICU72的发布做准备而需要的。
允许在日期字符串中使用U+202F,这将在ICU72下的toLocaleString("en-US")生成。

因此,这是有意为之,以支持ICU-72的下一个版本。因此,我们可以假设其他浏览器也会跟进这一变化。

[更新]

由于这个改变导致了太多的网页兼容性问题,Chrome对其Intl实现进行了修补,将这些U+202F字符转换回U+2000字符。显然,Firefox在此之前也做了相同的修补

英文:

This is apparently caused by this V8 CL

Here is the summary of this ChangeLog:

> [intl] Enhance Date parser to take Unicode SPACE
>
> This is needed to prepare for the landing of ICU72.
> Allow U+202F in the Date String, which the toLocaleString("en-US")
> will generate w/ ICU72.

So it's done on purpose, to support the next version of ICU-72. We can thus assume that other browsers will also follow on this.

[Update]

Since this change caused too many web-compat issues, Chrome did patch their Intl implementation against this ICU-72 change and converted these U+202F characters back to U+2000 characters. Apparently, Firefox did the same even before.

答案2

得分: 3

我认为这是不间断空格。
不间断空格
<br>由于它也出现在Edge110上,我认为它是从Chromium派生而来。

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-js -->

const event = new Date('August 19, 1975 23:15:30 GMT+00:00');
const localTime = event.toLocaleTimeString('en-US');
console.log(localTime);
console.log(localTime.indexOf(" "))
console.log(localTime.indexOf("\u{202F}"))
for (let i = 0; i < localTime.length; i++){
console.log(localTime.charCodeAt(i));
}

<!-- end snippet -->

英文:

I think it's non-breaking space.
Non-breaking space
<br>Since it also occurs on Edge110, I think it is derived from Chromium.

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-js -->

const event = new Date(&#39;August 19, 1975 23:15:30 GMT+00:00&#39;);
const localTime = event.toLocaleTimeString(&#39;en-US&#39;);
console.log(localTime);
console.log(localTime.indexOf(&quot; &quot;))
console.log(localTime.indexOf(&quot;\u{202F}&quot;))
for (let i = 0; i &lt; localTime.length; i++){
  console.log(localTime.charCodeAt(i));
}

<!-- end snippet -->

huangapple
  • 本文由 发表于 2023年2月10日 09:44:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/75406192.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定