File tree Expand file tree Collapse file tree 2 files changed +14
-2
lines changed Expand file tree Collapse file tree 2 files changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -138,16 +138,28 @@ def __call__(self, env):
138138 if self .dirty :
139139 env .errors .append (FluentCyclicReferenceError ("Cyclic reference" ))
140140 return FluentNone ()
141+ if env .part_count > MAX_PARTS :
142+ return ""
141143 self .dirty = True
144+ elements = self .elements
145+ remaining_parts = MAX_PARTS - env .part_count
146+ if len (self .elements ) > remaining_parts :
147+ elements = elements [:remaining_parts + 1 ]
148+ env .errors .append (ValueError ("Too many parts in message (> {0}), "
149+ "aborting." .format (MAX_PARTS )))
142150 retval = '' .join (
143- resolve (element (env ), env ) for element in self . elements
151+ resolve (element (env ), env ) for element in elements
144152 )
153+ env .part_count += len (elements )
145154 self .dirty = False
146155 return retval
147156
148157def resolve (fluentish , env ):
149158 if isinstance (fluentish , FluentType ):
150159 return fluentish .format (env .context ._babel_locale )
160+ if isinstance (fluentish , six .string_types ):
161+ if len (fluentish ) > MAX_PART_LENGTH :
162+ return fluentish [:MAX_PART_LENGTH ]
151163 return fluentish
152164
153165
Original file line number Diff line number Diff line change @@ -39,5 +39,5 @@ def test_max_expansions_protection(self):
3939 # Without protection, emptylolz will take a really long time to
4040 # evaluate, although it generates an empty message.
4141 val , errs = self .ctx .format ('emptylolz' )
42- self .assertEqual (val , '??? ' )
42+ self .assertEqual (val , '' )
4343 self .assertEqual (len (errs ), 1 )
You can’t perform that action at this time.
0 commit comments