From 7839e940bac9cc90fc6d8d322051d80fd7f40ec8 Mon Sep 17 00:00:00 2001
From: zzw <228544128@qq.com>
Date: 星期五, 02 十月 2026 18:25:30 +0800
Subject: [PATCH] fix: preserve codenames in table data cells
---
emergency-repair-web/src/utils/sensitive.js | 36 ++++++++++++++++++++++++++++--------
1 files changed, 28 insertions(+), 8 deletions(-)
diff --git a/emergency-repair-web/src/utils/sensitive.js b/emergency-repair-web/src/utils/sensitive.js
index b0e0513..c4bba53 100644
--- a/emergency-repair-web/src/utils/sensitive.js
+++ b/emergency-repair-web/src/utils/sensitive.js
@@ -12,6 +12,16 @@
!(realName.startsWith('[') && realName.endsWith(']'))
}
+// Table body cells render stored data, so they keep the codenames from the
+// source instead of being rewritten like headers, labels and placeholders.
+function isInsideTableCell(node) {
+ const element = node && node.nodeType === 1 ? node : node && node.parentElement
+ if (!element || !element.closest) {
+ return false
+ }
+ return !!element.closest('td')
+}
+
function replaceAsciiCodename(value, codename, realName) {
const pattern = new RegExp('(^|[^A-Za-z0-9])' + codename + '(?=$|[^A-Za-z0-9])', 'g')
return value.replace(pattern, function (match, prefix) {
@@ -57,11 +67,16 @@
return
}
if (root.nodeType === 1) {
- attributes.forEach(function (attribute) {
- replaceAttribute(root, attribute)
- })
+ if (!isInsideTableCell(root)) {
+ attributes.forEach(function (attribute) {
+ replaceAttribute(root, attribute)
+ })
+ }
}
root.querySelectorAll('[placeholder], [title], [aria-label]').forEach(function (element) {
+ if (isInsideTableCell(element)) {
+ return
+ }
attributes.forEach(function (attribute) {
replaceAttribute(element, attribute)
})
@@ -74,7 +89,9 @@
}
if (root.nodeType === 3) {
- replaceTextNode(root)
+ if (!isInsideTableCell(root)) {
+ replaceTextNode(root)
+ }
return
}
@@ -85,9 +102,10 @@
{
acceptNode: function (node) {
const parent = node.parentElement
- return parent && !SKIPPED_TAGS[parent.tagName]
- ? NodeFilter.FILTER_ACCEPT
- : NodeFilter.FILTER_REJECT
+ if (!parent || SKIPPED_TAGS[parent.tagName] || isInsideTableCell(parent)) {
+ return NodeFilter.FILTER_REJECT
+ }
+ return NodeFilter.FILTER_ACCEPT
}
}
)
@@ -107,7 +125,9 @@
observer = new MutationObserver(function (mutations) {
mutations.forEach(function (mutation) {
if (mutation.type === 'characterData') {
- replaceTextNode(mutation.target)
+ if (!isInsideTableCell(mutation.target)) {
+ replaceTextNode(mutation.target)
+ }
return
}
mutation.addedNodes.forEach(function (node) {
--
Gitblit v1.9.1