Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion core/src/main/resources/org/apache/spark/ui/static/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,28 @@ function getTimeZone() {
}
}

/* Custom log URLs are rendered as links only when they are http(s) or relative
* URLs; anything else is shown as plain text. Browsers strip ASCII whitespace
* and control characters when parsing URLs, so remove them before checking
* the scheme. */
function isHttpOrRelativeUrl(url) {
if (typeof url !== 'string') return false;
/* eslint-disable-next-line no-control-regex */
var normalized = url.replace(/[\u0000-\u0020]/g, '').toLowerCase();
return /^https?:\/\//.test(normalized) || !/^[a-z][a-z0-9+.-]*:/.test(normalized);
}

function formatLogsCells(execLogs, type) {
if (type !== 'display') return Object.keys(execLogs);
if (!execLogs) return;
var result = '';
$.each(execLogs, function (logName, logUrl) {
result += '<div><a href=' + logUrl + '>' + logName + '</a></div>'
// Custom log names and URLs can contain markup characters.
if (isHttpOrRelativeUrl(logUrl)) {
result += '<div><a href="' + escapeHtml(logUrl) + '">' + escapeHtml(logName) + '</a></div>'
} else {
result += '<div>' + escapeHtml(logName) + '</div>'
}
});
return result;
}
Expand Down Expand Up @@ -231,4 +247,16 @@ function createRESTEndPointForMiscellaneousProcess(appId) {
function getBaseURI() {
return document.baseURI || document.URL;
}

/* Escape a value for safe inclusion in HTML text content. Non-string values are
* coerced to a string first; null/undefined are returned unchanged. */
function escapeHtml(text) {
if (text === null || text === undefined) return text;
return String(text)
.replace(/&/g, "&amp;")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;")
.replace(/"/g, "&quot;")
.replace(/'/g, "&#039;");
}
/* eslint-enable no-unused-vars */