Bug 1436790 - Update Fluent in Gecko to 0.6.2. r?pike
MozReview-Commit-ID: BC2oTIGLips
--- a/intl/l10n/MessageContext.jsm
+++ b/intl/l10n/MessageContext.jsm
@@ -90,17 +90,18 @@ class RuntimeParser {
throw this.error(`Expected an entry to start
at the beginning of the file or on a new line.`);
}
const ch = this._source[this._index];
// 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;
}
if (ch === '[') {
this.skipSection();
return;
}
@@ -355,17 +356,19 @@ class RuntimeParser {
return this.getComplexPattern();
}
this._index = eol + 1;
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;
}
const lineStart = this._index;
this.skipInlineWS();
if (this._source[this._index] === '.') {
@@ -774,16 +777,20 @@ class RuntimeParser {
throw this.error('Expected "="');
}
this._index++;
this.skipInlineWS();
const val = this.getPattern();
+ if (val === null) {
+ throw this.error('Expected attribute to have a value');
+ }
+
if (typeof val === 'string') {
attrs[key] = val;
} else {
attrs[key] = {
val
};
}
@@ -821,21 +828,23 @@ class RuntimeParser {
}
this._index++;
const key = this.getVariantKey();
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();
}
return [variants, defaultIndex];
}
/**