mirror of
https://github.com/compiler-explorer/compiler-explorer.git
synced 2026-12-01 05:58:01 -06:00
Handle strings with spaces in them in asm output with horizontal whitespace squashing on. Fixes #883
This commit is contained in:
+14
-3
@@ -23,21 +23,32 @@
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
"use strict";
|
||||
|
||||
const findQuotes = /(.*?)("(?:[^"\\]|\\.)*")(.*)/;
|
||||
|
||||
class AsmRegex {
|
||||
constructor() {
|
||||
this.labelDef = /^([.a-z_$@][a-z0-9$_@.]*):/i;
|
||||
}
|
||||
|
||||
static filterAsmLine(line, filters) {
|
||||
if (!filters.trim) return line;
|
||||
static squashHorizontalWhitespace(line, atStart) {
|
||||
const quotes = line.match(findQuotes);
|
||||
if (quotes) {
|
||||
return this.squashHorizontalWhitespace(quotes[1], atStart) + quotes[2] +
|
||||
this.squashHorizontalWhitespace(quotes[3], false);
|
||||
}
|
||||
const splat = line.split(/\s+/);
|
||||
if (splat[0] === "") {
|
||||
if (splat[0] === "" && atStart) {
|
||||
// An indented line: preserve a two-space indent
|
||||
return " " + splat.slice(1).join(" ");
|
||||
} else {
|
||||
return splat.join(" ");
|
||||
}
|
||||
}
|
||||
|
||||
static filterAsmLine(line, filters) {
|
||||
if (!filters.trim) return line;
|
||||
return this.squashHorizontalWhitespace(line, true);
|
||||
}
|
||||
}
|
||||
|
||||
exports.AsmRegex = AsmRegex;
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
const AsmParser = require('../lib/asm-parser-vc');
|
||||
const AsmRegex = require('../lib/asmregex').AsmRegex;
|
||||
require('chai').should();
|
||||
|
||||
describe('ASM CL parser', () => {
|
||||
@@ -36,3 +37,23 @@ describe('ASM CL parser', () => {
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe('ASM regex base class', () => {
|
||||
it('should leave unfiltered lines alone', () => {
|
||||
const line = " this is a line";
|
||||
AsmRegex.filterAsmLine(line, {}).should.equal(line);
|
||||
});
|
||||
it('should use up internal whitespace when asked', () => {
|
||||
AsmRegex.filterAsmLine(" this is a line", {trim: true}).should.equal(" this is a line");
|
||||
AsmRegex.filterAsmLine("this is a line", {trim: true}).should.equal("this is a line");
|
||||
});
|
||||
it('should keep whitespace in strings', () => {
|
||||
AsmRegex.filterAsmLine('equs "this string"', {trim: true}).should.equal('equs "this string"');
|
||||
AsmRegex.filterAsmLine(' equs "this string"', {trim: true}).should.equal(' equs "this string"');
|
||||
AsmRegex.filterAsmLine('equs "this \\" string \\""', {trim: true}).should.equal('equs "this \\" string \\""');
|
||||
});
|
||||
it('should not get upset by mismatched strings', () => {
|
||||
AsmRegex.filterAsmLine("a \"string 'yeah", {trim: true}).should.equal("a \"string 'yeah");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user