From 5af03bf9b9687d4e113ff26991ce2184e1777e52 Mon Sep 17 00:00:00 2001 From: NetworkCats Date: Sun, 22 Mar 2026 17:51:20 +0800 Subject: [PATCH] fix: PO parser escape order, proxy endpoint consistency, and accessibility bugs --- src/handlers/api.rs | 4 ++-- src/i18n.rs | 3 ++- static/script.js | 14 ++++++++++---- static/style.css | 2 +- templates/index.html | 3 +++ 5 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/handlers/api.rs b/src/handlers/api.rs index 607677e..19118d1 100644 --- a/src/handlers/api.rs +++ b/src/handlers/api.rs @@ -81,8 +81,8 @@ fn proxy_field_handler( return Err(AppError::DbNotReady); } let ip = resolve_ip(headers, query, state.dev_mode)?; - let proxy = db::lookup_proxy(&state.db, ip).ok_or(AppError::DbLookupFailed)?; - Ok(format!("{}\n", field(&proxy))) + let value = db::lookup_proxy(&state.db, ip).map_or(false, |p| field(&p)); + Ok(format!("{value}\n")) } pub async fn asn_handler( diff --git a/src/i18n.rs b/src/i18n.rs index 8a639eb..195ab41 100644 --- a/src/i18n.rs +++ b/src/i18n.rs @@ -212,9 +212,10 @@ fn append_quoted(target: &mut String, quoted: &str) { if s.len() >= 2 && s.starts_with('"') && s.ends_with('"') { let inner = &s[1..s.len() - 1]; let unescaped = inner + .replace("\\\\", "\x00") .replace("\\n", "\n") .replace("\\\"", "\"") - .replace("\\\\", "\\"); + .replace('\x00', "\\"); target.push_str(&unescaped); } } diff --git a/static/script.js b/static/script.js index 0b95237..f2162ea 100644 --- a/static/script.js +++ b/static/script.js @@ -208,6 +208,9 @@ function initCopyIp(wrap){ var langTag=document.documentElement.getAttribute("lang")||"en"; var mmdbKeyMap={"en":"en","de":"de","es":"es","fr":"fr","ja":"ja","ru":"ru","pt":"pt-BR","zh-Hans":"zh-CN","zh-Hant":"zh-CN"}; var mmdbKey=mmdbKeyMap[langTag]||"en"; + var yesText=root.getAttribute("data-yes-text")||"Yes"; + var noText=root.getAttribute("data-no-text")||"No"; + var tableLabel=root.getAttribute("data-table-label")||"IP address information"; function localizedName(names){ if(!names)return ""; @@ -237,9 +240,9 @@ function initCopyIp(wrap){ function boolHtml(val){ if(val){ - return ''; + return ''+escapeHtml(yesText)+''; } - return ''; + return ''+escapeHtml(noText)+''; } function labelFor(key){ @@ -252,7 +255,7 @@ function initCopyIp(wrap){ html+=''; html+=''; - html+=''; + html+='
'; var asn=info.asn||{}; var asnNum=asn.autonomous_system_number; @@ -359,8 +362,11 @@ function initCopyIp(wrap){ }) .catch(function(){hideSkeleton();}); }else if(!primaryIsIPv6){ - fetch("/ip") + var controller2=new AbortController(); + var timeout2=setTimeout(function(){controller2.abort();},5000); + fetch("/ip",{signal:controller2.signal}) .then(function(r){ + clearTimeout(timeout2); if(!r.ok)throw new Error(r.status); return r.text(); }) diff --git a/static/style.css b/static/style.css index 1a92db4..7b1a094 100644 --- a/static/style.css +++ b/static/style.css @@ -154,7 +154,7 @@ main { .ip-copied-tooltip { position: absolute; - right: 0; + inset-inline-end: 0; top: 50%; translate: 0 -50%; font-size: 13px; diff --git a/templates/index.html b/templates/index.html index 3bb9c95..a4f564a 100644 --- a/templates/index.html +++ b/templates/index.html @@ -67,6 +67,9 @@