Skip to content

Backport MessageContext parser from fluent 0.6.2 #151

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 9, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Backport MessageContext parser changes from fluent 0.6.2
  - Correctly parse empty comment lines. (#149)
  - Forbid null attribute and variant values. (part of #150)
  • Loading branch information
stasm committed Feb 8, 2018
commit 864634f01fbd3b2274d02c595e383ef952859e4f
23 changes: 16 additions & 7 deletions fluent/src/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ class RuntimeParser {

// We don't care about comments or sections at runtime
if (ch === '/' ||
(ch === '#' && [' ', '#'].includes(this._source[this._index + 1]))) {
(ch === '#' &&
[' ', '#', '\n'].includes(this._source[this._index + 1]))) {
this.skipComment();
return;
}
Expand Down Expand Up @@ -340,7 +341,9 @@ class RuntimeParser {
this.skipBlankLines();

if (this._source[this._index] !== ' ') {
// No indentation means we're done with this message.
// No indentation means we're done with this message. Callers should check
// if the return value here is null. It may be OK for messages, but not OK
// for terms, attributes and variants.
return firstLineContent;
}

Expand Down Expand Up @@ -759,6 +762,10 @@ class RuntimeParser {

const val = this.getPattern();

if (val === null) {
throw this.error('Expected attribute to have a value');
}

if (typeof val === 'string') {
attrs[key] = val;
} else {
Expand Down Expand Up @@ -806,11 +813,13 @@ class RuntimeParser {

this.skipInlineWS();

const variant = {
key,
val: this.getPattern()
};
variants[index++] = variant;
const val = this.getPattern();

if (val === null) {
throw this.error('Expected variant to have a value');
}

variants[index++] = {key, val};

this.skipWS();
}
Expand Down