Bug 1436790 - Update Fluent in Gecko to 0.6.2. r?pike draft
authorZibi Braniecki <zbraniecki@mozilla.com>
Thu, 08 Feb 2018 10:59:29 -0800
changeset 752660 1a82557eada686c423e668347f474b2a0b19d96a
parent 752350 8cc2427a322caa1e2c09ca3957335f88e573dc7a
push id98337
push userbmo:gandalf@aviary.pl
push dateThu, 08 Feb 2018 18:59:35 +0000
reviewerspike
bugs1436790
milestone60.0a1
Bug 1436790 - Update Fluent in Gecko to 0.6.2. r?pike MozReview-Commit-ID: BC2oTIGLips
intl/l10n/MessageContext.jsm
--- 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];
   }
 
   /**