|
10 | 10 | using System.Linq; |
11 | 11 | using System.Numerics; |
12 | 12 | using System.Reflection; |
| 13 | +using System.Threading; |
13 | 14 | using System.Threading.Tasks; |
14 | 15 | using Newtonsoft.Json; |
15 | 16 | using NUnit.Framework; |
@@ -173,6 +174,83 @@ public void ArrayJoinShouldRespectLimitToString() |
173 | 174 | StringAssert.Contains("LimitToString", exception!.Message); |
174 | 175 | } |
175 | 176 |
|
| 177 | + [Test] |
| 178 | + public void ArraySizeShouldRespectLoopLimitForInternalIteration() |
| 179 | + { |
| 180 | + var context = new TemplateContext |
| 181 | + { |
| 182 | + LoopLimit = 5 |
| 183 | + }; |
| 184 | + context.PushGlobal(new ScriptObject |
| 185 | + { |
| 186 | + { "numbers", Enumerable.Range(0, 10) } |
| 187 | + }); |
| 188 | + |
| 189 | + var template = Template.Parse("{{ numbers | array.size }}"); |
| 190 | + |
| 191 | + var exception = Assert.Throws<ScriptRuntimeException>(() => template.Render(context)); |
| 192 | + |
| 193 | + StringAssert.Contains("iteration limit `5`", exception!.Message); |
| 194 | + } |
| 195 | + |
| 196 | + [Test] |
| 197 | + public void ArrayJoinShouldRespectLoopLimitForInternalIteration() |
| 198 | + { |
| 199 | + var context = new TemplateContext |
| 200 | + { |
| 201 | + LoopLimit = 5 |
| 202 | + }; |
| 203 | + context.PushGlobal(new ScriptObject |
| 204 | + { |
| 205 | + { "numbers", Enumerable.Range(0, 10) } |
| 206 | + }); |
| 207 | + |
| 208 | + var template = Template.Parse("{{ numbers | array.join '' }}"); |
| 209 | + |
| 210 | + var exception = Assert.Throws<ScriptRuntimeException>(() => template.Render(context)); |
| 211 | + |
| 212 | + StringAssert.Contains("iteration limit `5`", exception!.Message); |
| 213 | + } |
| 214 | + |
| 215 | + [Test] |
| 216 | + public void ArrayOffsetShouldRespectLoopLimitForInternalIteration() |
| 217 | + { |
| 218 | + var context = new TemplateContext |
| 219 | + { |
| 220 | + LoopLimit = 5 |
| 221 | + }; |
| 222 | + context.PushGlobal(new ScriptObject |
| 223 | + { |
| 224 | + { "numbers", Enumerable.Range(0, 10) } |
| 225 | + }); |
| 226 | + |
| 227 | + var template = Template.Parse("{{ numbers | array.offset 8 | array.first }}"); |
| 228 | + |
| 229 | + var exception = Assert.Throws<ScriptRuntimeException>(() => template.Render(context)); |
| 230 | + |
| 231 | + StringAssert.Contains("iteration limit `5`", exception!.Message); |
| 232 | + } |
| 233 | + |
| 234 | + [Test] |
| 235 | + public void InternalArrayEnumerationShouldCheckCancellation() |
| 236 | + { |
| 237 | + using var cancellation = new CancellationTokenSource(); |
| 238 | + cancellation.Cancel(); |
| 239 | + |
| 240 | + var context = new TemplateContext |
| 241 | + { |
| 242 | + CancellationToken = cancellation.Token |
| 243 | + }; |
| 244 | + context.PushGlobal(new ScriptObject |
| 245 | + { |
| 246 | + { "numbers", Enumerable.Range(0, 10) } |
| 247 | + }); |
| 248 | + |
| 249 | + var template = Template.Parse("{{ numbers | array.size }}"); |
| 250 | + |
| 251 | + Assert.Throws<ScriptAbortException>(() => template.Render(context)); |
| 252 | + } |
| 253 | + |
176 | 254 | [Test] |
177 | 255 | public void TestAssignValToDictionary() |
178 | 256 | { |
|
0 commit comments