refactor(ui): separate HTTP and HTTPS URL regex handling in log viewer

Split the single URL regex into two separate patterns for HTTP and HTTPS
to improve code clarity and maintainability, while preserving identical
link generation behavior.
[FR]: WebUI make hyperlinks clickable
Fixes #938
This commit is contained in:
bobokun 2025-09-06 21:38:09 -04:00
parent 2f3319ddab
commit ce8a418d4b
No known key found for this signature in database
GPG key ID: B73932169607D927
2 changed files with 12 additions and 5 deletions

View file

@ -1 +1 @@
4.6.1-develop15
4.6.1-develop16

View file

@ -318,16 +318,23 @@ class LogViewer {
* @returns {string} - HTML with clickable links
*/
makeLinksClickable(text) {
// URL regex pattern that matches http:// and https:// URLs
const urlRegex = /(https?:\/\/[^\s]+)/g;
// URL regex patterns for both HTTP and HTTPS - handled identically
const httpRegex = /(http:\/\/[^\s]+)/g;
const httpsRegex = /(https:\/\/[^\s]+)/g;
// Escape the entire text first for security
const escapedText = this.escapeHtml(text);
// Replace URLs with clickable links
return escapedText.replace(urlRegex, (url) => {
// Replace both HTTP and HTTPS URLs with identical clickable links
let result = escapedText.replace(httpRegex, (url) => {
return `<a href="${url}" target="_blank" rel="noopener noreferrer" class="log-link">${url}</a>`;
});
result = result.replace(httpsRegex, (url) => {
return `<a href="${url}" target="_blank" rel="noopener noreferrer" class="log-link">${url}</a>`;
});
return result;
}
scrollToTop() {