Use String.replaceAll() instead of String.replace() with /g flag (S7781)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-10 00:29:28 +08:00
parent 2b0dadedd4
commit ebd198e28d
5 changed files with 9 additions and 9 deletions

View File

@@ -921,7 +921,7 @@ function sliderValueRange(e, direction) {
// Update the slider
selectArea.value = closestIndexes;
// Reset the start/end calendar selection range
if (!isDateType) inputValue = Number(e.value.replace(/,/g, ""));
if (!isDateType) inputValue = Number(e.value.replaceAll(",", ""));
if (direction === "start") {
if (isDateType) {
endMinDate.value = e;

View File

@@ -523,7 +523,7 @@ function switchTab(newTab) {
function timeLabel(time) {
// sonar-qube prevent super-linear runtime due to backtracking; change * to ?
//
const label = getTimeLabel(time).replace(/\s+/g, " "); // Collapse all consecutive whitespace into a single space
const label = getTimeLabel(time).replaceAll(/\s+/g, " "); // Collapse all consecutive whitespace into a single space
const result = label.match(/^([\d.]+)\s?([a-zA-Z]+)$/); // add ^ and $ to meet sonar-qube need
return result;
}

View File

@@ -236,7 +236,7 @@ function onChange(event) {
* @param {KeyboardEvent} event - The keyup event.
*/
function onKeyUp(event) {
event.target.value = event.target.value.replace(/\D/g, "");
event.target.value = event.target.value.replaceAll(/\D/g, "");
if (event.keyCode === 38 || event.keyCode === 40) {
actionUpDown(event.target, event.keyCode === 38, true);
}

View File

@@ -12,9 +12,9 @@
*/
export function escapeHtml(str) {
return str
.replace(/&/g, "&amp;")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;")
.replace(/"/g, "&quot;")
.replace(/'/g, "&#039;");
.replaceAll("&", "&amp;")
.replaceAll("<", "&lt;")
.replaceAll(">", "&gt;")
.replaceAll('"', "&quot;")
.replaceAll("'", "&#039;");
}

View File

@@ -325,7 +325,7 @@ function onInput(e) {
*/
function getTextWidth(text, e) {
// Replace spaces with non-breaking spaces
const processedText = text.replace(/ /g, "\u00a0");
const processedText = text.replaceAll(" ", "\u00a0");
const hiddenSpan = document.createElement("span");
hiddenSpan.textContent = processedText;