diff --git a/root/static/scripts/common/i18n/expand2.js b/root/static/scripts/common/i18n/expand2.js index d1c56217bdb..ca8f39ed5c4 100644 --- a/root/static/scripts/common/i18n/expand2.js +++ b/root/static/scripts/common/i18n/expand2.js @@ -206,7 +206,7 @@ export const createTextContentParser = ( return mapValue(text); }; -const varSubst = /^\{([0-9A-z_]+)\}/; +const varSubst = /^\{([0-9A-z_ ]+)\}/; export const createVarSubstParser = ( argFilter: (V) => T, ): Parser => saveMatch( @@ -225,7 +225,7 @@ export const createVarSubstParser = ( export const parseStringVarSubst: Parser = createVarSubstParser(getString); -const condSubstStart = /^\{([0-9A-z_]+):/; +const condSubstStart = /^\{([0-9A-z_ ]+):/; const verticalPipe = /^\|/; export const substEnd: RegExp = /^}/; export const createCondSubstParser = ( diff --git a/root/static/scripts/common/i18n/expand2react.js b/root/static/scripts/common/i18n/expand2react.js index cbaa1f01966..fa541130d9a 100644 --- a/root/static/scripts/common/i18n/expand2react.js +++ b/root/static/scripts/common/i18n/expand2react.js @@ -53,7 +53,7 @@ type Output = Expand2ReactOutput; const textContent = /^[^<>{}]+/; const condSubstThenTextContent = /^[^<>{}|]+/; const percentSign = /(%)/; -const linkSubstStart = /^\{([0-9A-z_]+)\|/; +const linkSubstStart = /^\{([0-9A-z_ ]+)\|/; const htmlTagStart = /^<(?=[a-z])/; const htmlTagName = /^(a|abbr|br|code|em|h1|h2|h3|h4|h5|h6|hr|li|ol|p|span|strong|ul)(?=[\s\/>])/; const htmlTagEnd = /^>/; diff --git a/root/static/scripts/tests/i18n/expand2.js b/root/static/scripts/tests/i18n/expand2.js index 16b6b846cc8..3f689e98d14 100644 --- a/root/static/scripts/tests/i18n/expand2.js +++ b/root/static/scripts/tests/i18n/expand2.js @@ -11,7 +11,7 @@ import expand2text, { } from '../../common/i18n/expand2text.js'; test('expand2', function (t) { - t.plan(69); + t.plan(70); let error = ''; const consoleError = console.error; @@ -46,6 +46,7 @@ test('expand2', function (t) { ); expandText('An {apple_fruit}', null, 'An {apple_fruit}'); expandText('An {apple_fruit}', {apple_fruit: 'apple'}, 'An apple'); + expandText('An {apple fruit}', {'apple fruit': 'apple'}, 'An apple'); expandText('A {number}', {number: 1}, 'A 1'); expandHtml('{null} value', {null: null}, ' value'); t.equal(error, ''); diff --git a/t/lib/t/MusicBrainz/Server/Translation.pm b/t/lib/t/MusicBrainz/Server/Translation.pm index 5950c67970c..ba4ac4830a1 100644 --- a/t/lib/t/MusicBrainz/Server/Translation.pm +++ b/t/lib/t/MusicBrainz/Server/Translation.pm @@ -12,9 +12,15 @@ test 'Check _expand_link' => sub { is(MusicBrainz::Server::Translation->instance->expand('An {apple_fruit}', apple_fruit => 'apple'), 'An apple', 'Simple replacement'); + is(MusicBrainz::Server::Translation->instance->expand('An {apple fruit}', + 'apple fruit' => 'apple'), + 'An apple', 'Simple replacement with spaces in key'); is(MusicBrainz::Server::Translation->instance->expand('An {apple_fruit|Apple}', apple_fruit => 'http://www.apple.com'), 'An Apple', 'Replacement with links'); + is(MusicBrainz::Server::Translation->instance->expand('An {apple fruit|Apple}', + 'apple fruit' => 'http://www.apple.com'), + 'An Apple', 'Replacement with links and spaces in key'); is(MusicBrainz::Server::Translation->instance->expand('A {apple_fruit|apple}', apple_fruit => 'http://www.apple.com', apple => 'pear'), 'A pear', 'Replacement with link description evaluation');