This is an automated email from the ASF dual-hosted git repository.
potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push:
new 2f9b23d568 Recognize quotes when parsing urls in logs (#40508)
2f9b23d568 is described below
commit 2f9b23d568fb12edcb48fefd010fef8ec45dd12e
Author: Jacob Lee <[email protected]>
AuthorDate: Tue Jul 2 23:18:09 2024 +0900
Recognize quotes when parsing urls in logs (#40508)
---------
Co-authored-by: Jacob Lee <[email protected]>
---
.../dag/details/taskInstance/Logs/utils.test.tsx | 25 +++++++++++++++++++---
.../js/dag/details/taskInstance/Logs/utils.ts | 2 +-
2 files changed, 23 insertions(+), 4 deletions(-)
diff --git a/airflow/www/static/js/dag/details/taskInstance/Logs/utils.test.tsx
b/airflow/www/static/js/dag/details/taskInstance/Logs/utils.test.tsx
index aa835985d7..bcebb22ec9 100644
--- a/airflow/www/static/js/dag/details/taskInstance/Logs/utils.test.tsx
+++ b/airflow/www/static/js/dag/details/taskInstance/Logs/utils.test.tsx
@@ -38,6 +38,7 @@ const mockTaskLog = `
[2022-06-04 00:00:01,921] {dagbag.py:507} INFO - Filling up the DagBag from
/files/dags/test_ui_grid.py
[2022-06-04 00:00:01,964] {task_command.py:377} INFO - Running <TaskInstance:
test_ui_grid.section_1.get_entry_group scheduled__2022-06-03T00:00:00+00:00
[running]> on host 5d28cfda3219
[2022-06-04 00:00:02,010] {taskinstance.py:1548} WARNING - Exporting env vars:
AIRFLOW_CTX_DAG_OWNER=*** AIRFLOW_CTX_DAG_ID=test_ui_grid
+[2024-07-01 00:00:02,010] {taskinstance.py:1548} INFO - Url parsing test =>
"https://apple.com", "https://google.com"
`;
describe("Test Logs Utils.", () => {
@@ -64,7 +65,7 @@ describe("Test Logs Utils.", () => {
test.each([
{
logLevelFilters: [LogLevel.INFO],
- expectedNumberOfLines: 11,
+ expectedNumberOfLines: 12,
expectedNumberOfFileSources: 4,
},
{
@@ -111,7 +112,7 @@ describe("Test Logs Utils.", () => {
"taskinstance.py",
]);
const lines = parsedLogs!.split("\n");
- expect(lines).toHaveLength(7);
+ expect(lines).toHaveLength(8);
lines.forEach((line) => expect(line).toContain("taskinstance.py"));
});
@@ -131,7 +132,25 @@ describe("Test Logs Utils.", () => {
"taskinstance.py",
]);
const lines = parsedLogs!.split("\n");
- expect(lines).toHaveLength(7);
+ expect(lines).toHaveLength(8);
lines.forEach((line) => expect(line).toMatch(/INFO|WARNING/));
});
+
+ test("parseLogs function with quoted urls", () => {
+ const { parsedLogs } = parseLogs(
+ mockTaskLog,
+ null,
+ [LogLevel.INFO, LogLevel.WARNING],
+ ["taskinstance.py"],
+ []
+ );
+
+ const lines = parsedLogs!.split("\n");
+ expect(lines[lines.length - 1]).toContain(
+ '<a href="https://apple.com" target="_blank" style="color: blue;
text-decoration: underline;">https://apple.com</a>'
+ );
+ expect(lines[lines.length - 1]).toContain(
+ '<a href="https://google.com" target="_blank" style="color: blue;
text-decoration: underline;">https://google.com</a>'
+ );
+ });
});
diff --git a/airflow/www/static/js/dag/details/taskInstance/Logs/utils.ts
b/airflow/www/static/js/dag/details/taskInstance/Logs/utils.ts
index 0de5676916..49e922a91d 100644
--- a/airflow/www/static/js/dag/details/taskInstance/Logs/utils.ts
+++ b/airflow/www/static/js/dag/details/taskInstance/Logs/utils.ts
@@ -74,7 +74,7 @@ export const parseLogs = (
const ansiUp = new AnsiUp();
ansiUp.url_allowlist = {};
- const urlRegex = /((https?:\/\/|http:\/\/)[^\s]+)/g;
+ const urlRegex = /((https?:\/\/|http:\/\/)(?:(?!'|")[^\s])+)/g;
// Detect log groups which can be collapsed
// Either in Github like format '::group::<group name>' to '::endgroup::'
// see
https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#grouping-log-lines