From 2c72257128aa79179f0fd1b26b7e9b4232549cbf Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Thu, 30 Mar 2023 23:28:18 +0800 Subject: [PATCH] remove trailing "\r\n" or "\n" --- web_src/js/components/RepoActionView.test.js | 2 ++ web_src/js/components/RepoActionView.vue | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/web_src/js/components/RepoActionView.test.js b/web_src/js/components/RepoActionView.test.js index 24c2f75527a35..186a9d36689c2 100644 --- a/web_src/js/components/RepoActionView.test.js +++ b/web_src/js/components/RepoActionView.test.js @@ -4,6 +4,8 @@ import {processConsoleLine} from './RepoActionView.vue'; test('processConsoleLine', () => { expect(processConsoleLine('abc')).toEqual('abc'); + expect(processConsoleLine('abc\n')).toEqual('abc'); + expect(processConsoleLine('abc\r\n')).toEqual('abc'); expect(processConsoleLine('\r')).toEqual(''); expect(processConsoleLine('\rx\rabc')).toEqual('abc'); expect(processConsoleLine('\rabc\rx\r')).toEqual('xbc'); diff --git a/web_src/js/components/RepoActionView.vue b/web_src/js/components/RepoActionView.vue index 66e65424415d1..3faa13fbc3533 100644 --- a/web_src/js/components/RepoActionView.vue +++ b/web_src/js/components/RepoActionView.vue @@ -308,6 +308,11 @@ export function initRepositoryActionView() { } export function processConsoleLine(line) { + if (line.endsWith('\r\n')) { + line = line.substring(0, line.length - 2); + } else if (line.endsWith('\n')) { + line = line.substring(0, line.length - 1); + } if (!line.includes('\r')) return line; // handle "\rReading...1%\rReading...5%\rReading...100%", only show the final message