Skip to content

Commit

Permalink
remove trailing "\r\n" or "\n"
Browse files Browse the repository at this point in the history
  • Loading branch information
wxiaoguang committed Mar 30, 2023
1 parent 3799a92 commit 2c72257
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions web_src/js/components/RepoActionView.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
5 changes: 5 additions & 0 deletions web_src/js/components/RepoActionView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2c72257

Please sign in to comment.