Skip to content

Commit

Permalink
MBS-13496: Support attributes with spaces in link phrase interpolation
Browse files Browse the repository at this point in the history
Using the new "a cappella" attribute was breaking link phrase
interpolation, because spaces were not accepted as part of the
interpolated "variable name".
We already had several attributes with spaces in their name
though, we just had gotten lucky we were not using any of them
in link phrases until now.

Just adding spaces to the allowed characters doesn't seem to cause
any new issues, so it seems good enough for our needs.
  • Loading branch information
reosarevok committed Feb 26, 2024
1 parent 1873cac commit 276a3c0
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions root/static/scripts/common/i18n/expand2.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ export const createTextContentParser = <T, V>(
return mapValue(text);
};

const varSubst = /^\{([0-9A-z_]+)\}/;
const varSubst = /^\{([0-9A-z_ ]+)\}/;
export const createVarSubstParser = <T, V>(
argFilter: (V) => T,
): Parser<T | string | NO_MATCH, V> => saveMatch(
Expand All @@ -225,7 +225,7 @@ export const createVarSubstParser = <T, V>(
export const parseStringVarSubst: Parser<string | NO_MATCH, mixed> =
createVarSubstParser<string, mixed>(getString);

const condSubstStart = /^\{([0-9A-z_]+):/;
const condSubstStart = /^\{([0-9A-z_ ]+):/;
const verticalPipe = /^\|/;
export const substEnd: RegExp = /^}/;
export const createCondSubstParser = <T, V: Expand2ReactInput>(
Expand Down
2 changes: 1 addition & 1 deletion root/static/scripts/common/i18n/expand2react.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = /^>/;
Expand Down
3 changes: 2 additions & 1 deletion root/static/scripts/tests/i18n/expand2.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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, '');
Expand Down

0 comments on commit 276a3c0

Please sign in to comment.