Skip to content

Commit d879d73

Browse files
jptarantomarcalexiei
authored andcommitted
fix: remove whitespace and line breaks from map keys
1 parent caae3a5 commit d879d73

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

src/process-value.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ function getKeyFromMapString(mapString, keyParameter) {
1212
const keyValue = keyParameter.replace(/\s/g, '');
1313
// remove open and close parenthesis from the map string
1414
mapString = mapString.slice(1, -1);
15+
// remove all line breaks from the map string
16+
mapString = mapString.replace(/(\r\n|\n|\r)/gm, '');
1517

1618
let isParsingKey = true;
1719
let hasFinishedParsingValue = false;
@@ -55,6 +57,8 @@ function getKeyFromMapString(mapString, keyParameter) {
5557
}
5658

5759
if (hasFinishedParsingValue) {
60+
// remove whitespace from parsed key
61+
key = key.replace(/\s/g, '');
5862
if (key === keyValue) {
5963
return value.trim();
6064
}

test/test.plugin.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,9 @@ test('it should throw an error when key is not defined', t => {
6565

6666
t.is(testError.message, `postcss – map-get – unable to find “${requestedKey}“ key inside map “${map}“`);
6767
});
68+
69+
test('it should remove line breaks and space from map key only', t => {
70+
const expected = '.foo {border: 1px solid black}';
71+
const value = '.foo {border: map-get((\n border: 1px solid black), border)}';
72+
t.is(processing(value), expected);
73+
});

0 commit comments

Comments
 (0)