yellow-brick-road 0.2.3 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,3 @@
1
1
  module YellowBrickRoad
2
- VERSION = '0.2.3'
2
+ VERSION = '0.2.4'
3
3
  end
@@ -0,0 +1,1417 @@
1
+ /*
2
+ * Copyright 2008 Google Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ /**
18
+ * @fileoverview
19
+ * Utility functions and classes for Soy.
20
+ *
21
+ * <p>
22
+ * The top portion of this file contains utilities for Soy users:<ul>
23
+ * <li> soy.StringBuilder: Compatible with the 'stringbuilder' code style.
24
+ * <li> soy.renderElement: Render template and set as innerHTML of an element.
25
+ * <li> soy.renderAsFragment: Render template and return as HTML fragment.
26
+ * </ul>
27
+ *
28
+ * <p>
29
+ * The bottom portion of this file contains utilities that should only be called
30
+ * by Soy-generated JS code. Please do not use these functions directly from
31
+ * your hand-writen code. Their names all start with '$$'.
32
+ *
33
+ */
34
+
35
+ goog.provide('soy');
36
+ goog.provide('soy.StringBuilder');
37
+ goog.provide('soy.esc');
38
+ goog.provide('soydata');
39
+ goog.provide('soydata.SanitizedHtml');
40
+ goog.provide('soydata.SanitizedHtmlAttribute');
41
+ goog.provide('soydata.SanitizedJsStrChars');
42
+ goog.provide('soydata.SanitizedUri');
43
+
44
+ goog.require('goog.asserts');
45
+ goog.require('goog.dom.DomHelper');
46
+ goog.require('goog.format');
47
+ goog.require('goog.i18n.BidiFormatter');
48
+ goog.require('goog.i18n.bidi');
49
+ goog.require('goog.soy');
50
+ goog.require('goog.string');
51
+ goog.require('goog.string.StringBuffer');
52
+
53
+
54
+ // -----------------------------------------------------------------------------
55
+ // StringBuilder (compatible with the 'stringbuilder' code style).
56
+
57
+
58
+ /**
59
+ * Utility class to facilitate much faster string concatenation in IE,
60
+ * using Array.join() rather than the '+' operator. For other browsers
61
+ * we simply use the '+' operator.
62
+ *
63
+ * @param {Object} var_args Initial items to append,
64
+ * e.g., new soy.StringBuilder('foo', 'bar').
65
+ * @constructor
66
+ */
67
+ soy.StringBuilder = goog.string.StringBuffer;
68
+
69
+
70
+ // -----------------------------------------------------------------------------
71
+ // soydata: Defines typed strings, e.g. an HTML string {@code "a<b>c"} is
72
+ // semantically distinct from the plain text string {@code "a<b>c"} and smart
73
+ // templates can take that distinction into account.
74
+
75
+ /**
76
+ * A type of textual content.
77
+ * @enum {number}
78
+ */
79
+ soydata.SanitizedContentKind = {
80
+
81
+ /**
82
+ * A snippet of HTML that does not start or end inside a tag, comment, entity,
83
+ * or DOCTYPE; and that does not contain any executable code
84
+ * (JS, {@code <object>}s, etc.) from a different trust domain.
85
+ */
86
+ HTML: 0,
87
+
88
+ /**
89
+ * A sequence of code units that can appear between quotes (either kind) in a
90
+ * JS program without causing a parse error, and without causing any side
91
+ * effects.
92
+ * <p>
93
+ * The content should not contain unescaped quotes, newlines, or anything else
94
+ * that would cause parsing to fail or to cause a JS parser to finish the
95
+ * string its parsing inside the content.
96
+ * <p>
97
+ * The content must also not end inside an escape sequence ; no partial octal
98
+ * escape sequences or odd number of '{@code \}'s at the end.
99
+ */
100
+ JS_STR_CHARS: 1,
101
+
102
+ /** A properly encoded portion of a URI. */
103
+ URI: 2,
104
+
105
+ /** An attribute name and value such as {@code dir="ltr"}. */
106
+ HTML_ATTRIBUTE: 3
107
+ };
108
+
109
+
110
+ /**
111
+ * A string-like object that carries a content-type.
112
+ * @param {string} content
113
+ * @constructor
114
+ * @private
115
+ */
116
+ soydata.SanitizedContent = function(content) {
117
+ /**
118
+ * The textual content.
119
+ * @type {string}
120
+ */
121
+ this.content = content;
122
+ };
123
+
124
+ /** @type {soydata.SanitizedContentKind} */
125
+ soydata.SanitizedContent.prototype.contentKind;
126
+
127
+ /** @override */
128
+ soydata.SanitizedContent.prototype.toString = function() {
129
+ return this.content;
130
+ };
131
+
132
+
133
+ /**
134
+ * Content of type {@link soydata.SanitizedContentKind.HTML}.
135
+ * @param {string} content A string of HTML that can safely be embedded in
136
+ * a PCDATA context in your app. If you would be surprised to find that an
137
+ * HTML sanitizer produced {@code s} (e.g. it runs code or fetches bad URLs)
138
+ * and you wouldn't write a template that produces {@code s} on security or
139
+ * privacy grounds, then don't pass {@code s} here.
140
+ * @constructor
141
+ * @extends {soydata.SanitizedContent}
142
+ */
143
+ soydata.SanitizedHtml = function(content) {
144
+ soydata.SanitizedContent.call(this, content);
145
+ };
146
+ goog.inherits(soydata.SanitizedHtml, soydata.SanitizedContent);
147
+
148
+ /** @override */
149
+ soydata.SanitizedHtml.prototype.contentKind = soydata.SanitizedContentKind.HTML;
150
+
151
+
152
+ /**
153
+ * Content of type {@link soydata.SanitizedContentKind.JS_STR_CHARS}.
154
+ * @param {string} content A string of JS that when evaled, produces a
155
+ * value that does not depend on any sensitive data and has no side effects
156
+ * <b>OR</b> a string of JS that does not reference any variables or have
157
+ * any side effects not known statically to the app authors.
158
+ * @constructor
159
+ * @extends {soydata.SanitizedContent}
160
+ */
161
+ soydata.SanitizedJsStrChars = function(content) {
162
+ soydata.SanitizedContent.call(this, content);
163
+ };
164
+ goog.inherits(soydata.SanitizedJsStrChars, soydata.SanitizedContent);
165
+
166
+ /** @override */
167
+ soydata.SanitizedJsStrChars.prototype.contentKind =
168
+ soydata.SanitizedContentKind.JS_STR_CHARS;
169
+
170
+
171
+ /**
172
+ * Content of type {@link soydata.SanitizedContentKind.URI}.
173
+ * @param {string} content A chunk of URI that the caller knows is safe to
174
+ * emit in a template.
175
+ * @constructor
176
+ * @extends {soydata.SanitizedContent}
177
+ */
178
+ soydata.SanitizedUri = function(content) {
179
+ soydata.SanitizedContent.call(this, content);
180
+ };
181
+ goog.inherits(soydata.SanitizedUri, soydata.SanitizedContent);
182
+
183
+ /** @override */
184
+ soydata.SanitizedUri.prototype.contentKind = soydata.SanitizedContentKind.URI;
185
+
186
+
187
+ /**
188
+ * Content of type {@link soydata.SanitizedContentKind.HTML_ATTRIBUTE}.
189
+ * @param {string} content An attribute name and value, such as
190
+ * {@code dir="ltr"}.
191
+ * @constructor
192
+ * @extends {soydata.SanitizedContent}
193
+ */
194
+ soydata.SanitizedHtmlAttribute = function(content) {
195
+ soydata.SanitizedContent.call(this, content);
196
+ };
197
+ goog.inherits(soydata.SanitizedHtmlAttribute, soydata.SanitizedContent);
198
+
199
+ /** @override */
200
+ soydata.SanitizedHtmlAttribute.prototype.contentKind =
201
+ soydata.SanitizedContentKind.HTML_ATTRIBUTE;
202
+
203
+
204
+ // -----------------------------------------------------------------------------
205
+ // Public utilities.
206
+
207
+
208
+ /**
209
+ * Helper function to render a Soy template and then set the output string as
210
+ * the innerHTML of an element. It is recommended to use this helper function
211
+ * instead of directly setting innerHTML in your hand-written code, so that it
212
+ * will be easier to audit the code for cross-site scripting vulnerabilities.
213
+ *
214
+ * NOTE: New code should consider using goog.soy.renderElement instead.
215
+ *
216
+ * @param {Element} element The element whose content we are rendering.
217
+ * @param {Function} template The Soy template defining the element's content.
218
+ * @param {Object=} opt_templateData The data for the template.
219
+ * @param {Object=} opt_injectedData The injected data for the template.
220
+ */
221
+ soy.renderElement = goog.soy.renderElement;
222
+
223
+
224
+ /**
225
+ * Helper function to render a Soy template into a single node or a document
226
+ * fragment. If the rendered HTML string represents a single node, then that
227
+ * node is returned (note that this is *not* a fragment, despite them name of
228
+ * the method). Otherwise a document fragment is returned containing the
229
+ * rendered nodes.
230
+ *
231
+ * NOTE: New code should consider using goog.soy.renderAsFragment
232
+ * instead (note that the arguments are different).
233
+ *
234
+ * @param {Function} template The Soy template defining the element's content.
235
+ * @param {Object=} opt_templateData The data for the template.
236
+ * @param {Document=} opt_document The document used to create DOM nodes. If not
237
+ * specified, global document object is used.
238
+ * @param {Object=} opt_injectedData The injected data for the template.
239
+ * @return {!Node} The resulting node or document fragment.
240
+ */
241
+ soy.renderAsFragment = function(
242
+ template, opt_templateData, opt_document, opt_injectedData) {
243
+ return goog.soy.renderAsFragment(
244
+ template, opt_templateData, opt_injectedData,
245
+ new goog.dom.DomHelper(opt_document));
246
+ };
247
+
248
+
249
+ /**
250
+ * Helper function to render a Soy template into a single node. If the rendered
251
+ * HTML string represents a single node, then that node is returned. Otherwise,
252
+ * a DIV element is returned containing the rendered nodes.
253
+ *
254
+ * NOTE: New code should consider using goog.soy.renderAsElement
255
+ * instead (note that the arguments are different).
256
+ *
257
+ * @param {Function} template The Soy template defining the element's content.
258
+ * @param {Object=} opt_templateData The data for the template.
259
+ * @param {Document=} opt_document The document used to create DOM nodes. If not
260
+ * specified, global document object is used.
261
+ * @param {Object=} opt_injectedData The injected data for the template.
262
+ * @return {!Element} Rendered template contents, wrapped in a parent DIV
263
+ * element if necessary.
264
+ */
265
+ soy.renderAsElement = function(
266
+ template, opt_templateData, opt_document, opt_injectedData) {
267
+ return goog.soy.renderAsElement(
268
+ template, opt_templateData, opt_injectedData,
269
+ new goog.dom.DomHelper(opt_document));
270
+ };
271
+
272
+
273
+ // -----------------------------------------------------------------------------
274
+ // Below are private utilities to be used by Soy-generated code only.
275
+
276
+
277
+ /**
278
+ * Builds an augmented data object to be passed when a template calls another,
279
+ * and needs to pass both original data and additional params. The returned
280
+ * object will contain both the original data and the additional params. If the
281
+ * same key appears in both, then the value from the additional params will be
282
+ * visible, while the value from the original data will be hidden. The original
283
+ * data object will be used, but not modified.
284
+ *
285
+ * @param {!Object} origData The original data to pass.
286
+ * @param {Object} additionalParams The additional params to pass.
287
+ * @return {Object} An augmented data object containing both the original data
288
+ * and the additional params.
289
+ */
290
+ soy.$$augmentData = function(origData, additionalParams) {
291
+
292
+ // Create a new object whose '__proto__' field is set to origData.
293
+ /** @constructor */
294
+ function TempCtor() {}
295
+ TempCtor.prototype = origData;
296
+ var newData = new TempCtor();
297
+
298
+ // Add the additional params to the new object.
299
+ for (var key in additionalParams) {
300
+ newData[key] = additionalParams[key];
301
+ }
302
+
303
+ return newData;
304
+ };
305
+
306
+
307
+ /**
308
+ * Gets the keys in a map as an array. There are no guarantees on the order.
309
+ * @param {Object} map The map to get the keys of.
310
+ * @return {Array.<string>} The array of keys in the given map.
311
+ */
312
+ soy.$$getMapKeys = function(map) {
313
+ var mapKeys = [];
314
+ for (var key in map) {
315
+ mapKeys.push(key);
316
+ }
317
+ return mapKeys;
318
+ };
319
+
320
+
321
+ /**
322
+ * Gets a consistent unique id for the given delegate template name. Two calls
323
+ * to this function will return the same id if and only if the input names are
324
+ * the same.
325
+ *
326
+ * <p> Important: This function must always be called with a string constant.
327
+ *
328
+ * <p> If Closure Compiler is not being used, then this is just this identity
329
+ * function. If Closure Compiler is being used, then each call to this function
330
+ * will be replaced with a short string constant, which will be consistent per
331
+ * input name.
332
+ *
333
+ * @param {string} delTemplateName The delegate template name for which to get a
334
+ * consistent unique id.
335
+ * @return {string} A unique id that is consistent per input name.
336
+ *
337
+ * @consistentIdGenerator
338
+ */
339
+ soy.$$getDelegateId = function(delTemplateName) {
340
+ return delTemplateName;
341
+ };
342
+
343
+
344
+ /**
345
+ * Map from registered delegate template id/name to the priority of the
346
+ * implementation.
347
+ * @type {Object}
348
+ * @private
349
+ */
350
+ soy.$$DELEGATE_REGISTRY_PRIORITIES_ = {};
351
+
352
+ /**
353
+ * Map from registered delegate template id/name to the implementation function.
354
+ * @type {Object}
355
+ * @private
356
+ */
357
+ soy.$$DELEGATE_REGISTRY_FUNCTIONS_ = {};
358
+
359
+
360
+ /**
361
+ * Registers a delegate implementation. If the same delegate template id/name
362
+ * has been registered previously, then priority values are compared and only
363
+ * the higher priority implementation is stored (if priorities are equal, an
364
+ * error is thrown).
365
+ *
366
+ * @param {string} delTemplateId The delegate template id/name to register.
367
+ * @param {number} delPriority The implementation's priority value.
368
+ * @param {Function} delFn The implementation function.
369
+ */
370
+ soy.$$registerDelegateFn = function(delTemplateId, delPriority, delFn) {
371
+ var mapKey = 'key_' + delTemplateId;
372
+ var currPriority = soy.$$DELEGATE_REGISTRY_PRIORITIES_[mapKey];
373
+ if (currPriority === undefined || delPriority > currPriority) {
374
+ // Registering new or higher-priority function: replace registry entry.
375
+ soy.$$DELEGATE_REGISTRY_PRIORITIES_[mapKey] = delPriority;
376
+ soy.$$DELEGATE_REGISTRY_FUNCTIONS_[mapKey] = delFn;
377
+ } else if (delPriority == currPriority) {
378
+ // Registering same-priority function: error.
379
+ throw Error(
380
+ 'Encountered two active delegates with same priority (id/name "' +
381
+ delTemplateId + '").');
382
+ } else {
383
+ // Registering lower-priority function: do nothing.
384
+ }
385
+ };
386
+
387
+
388
+ /**
389
+ * Retrieves the (highest-priority) implementation that has been registered for
390
+ * a given delegate template id/name. If no implementation has been registered
391
+ * for the id/name, then returns an implementation that is equivalent to an
392
+ * empty template (i.e. rendered output would be empty string).
393
+ *
394
+ * @param {string} delTemplateId The delegate template id/name to get.
395
+ * @return {Function} The retrieved implementation function.
396
+ */
397
+ soy.$$getDelegateFn = function(delTemplateId) {
398
+ var delFn = soy.$$DELEGATE_REGISTRY_FUNCTIONS_['key_' + delTemplateId];
399
+ return delFn ? delFn : soy.$$EMPTY_TEMPLATE_FN_;
400
+ };
401
+
402
+
403
+ /**
404
+ * Private helper soy.$$getDelegateFn(). This is the empty template function
405
+ * that is returned whenever there's no delegate implementation found.
406
+ *
407
+ * @param {Object.<string, *>=} opt_data
408
+ * @param {soy.StringBuilder=} opt_sb
409
+ * @param {Object.<string, *>=} opt_ijData
410
+ * @return {string}
411
+ * @private
412
+ */
413
+ soy.$$EMPTY_TEMPLATE_FN_ = function(opt_data, opt_sb, opt_ijData) {
414
+ return '';
415
+ };
416
+
417
+
418
+ // -----------------------------------------------------------------------------
419
+ // Escape/filter/normalize.
420
+
421
+
422
+ /**
423
+ * Escapes HTML special characters in a string. Escapes double quote '"' in
424
+ * addition to '&', '<', and '>' so that a string can be included in an HTML
425
+ * tag attribute value within double quotes.
426
+ * Will emit known safe HTML as-is.
427
+ *
428
+ * @param {*} value The string-like value to be escaped. May not be a string,
429
+ * but the value will be coerced to a string.
430
+ * @return {string} An escaped version of value.
431
+ */
432
+ soy.$$escapeHtml = function(value) {
433
+ if (typeof value === 'object' && value &&
434
+ value.contentKind === soydata.SanitizedContentKind.HTML) {
435
+ return value.content;
436
+ }
437
+ return soy.esc.$$escapeHtmlHelper(value);
438
+ };
439
+
440
+
441
+ /**
442
+ * Escapes HTML special characters in a string so that it can be embedded in
443
+ * RCDATA.
444
+ * <p>
445
+ * Escapes HTML special characters so that the value will not prematurely end
446
+ * the body of a tag like {@code <textarea>} or {@code <title>}. RCDATA tags
447
+ * cannot contain other HTML entities, so it is not strictly necessary to escape
448
+ * HTML special characters except when part of that text looks like an HTML
449
+ * entity or like a close tag : {@code </textarea>}.
450
+ * <p>
451
+ * Will normalize known safe HTML to make sure that sanitized HTML (which could
452
+ * contain an innocuous {@code </textarea>} don't prematurely end an RCDATA
453
+ * element.
454
+ *
455
+ * @param {*} value The string-like value to be escaped. May not be a string,
456
+ * but the value will be coerced to a string.
457
+ * @return {string} An escaped version of value.
458
+ */
459
+ soy.$$escapeHtmlRcdata = function(value) {
460
+ if (typeof value === 'object' && value &&
461
+ value.contentKind === soydata.SanitizedContentKind.HTML) {
462
+ return soy.esc.$$normalizeHtmlHelper(value.content);
463
+ }
464
+ return soy.esc.$$escapeHtmlHelper(value);
465
+ };
466
+
467
+
468
+ /**
469
+ * Removes HTML tags from a string of known safe HTML so it can be used as an
470
+ * attribute value.
471
+ *
472
+ * @param {*} value The HTML to be escaped. May not be a string, but the
473
+ * value will be coerced to a string.
474
+ * @return {string} A representation of value without tags, HTML comments, or
475
+ * other content.
476
+ */
477
+ soy.$$stripHtmlTags = function(value) {
478
+ return String(value).replace(soy.esc.$$HTML_TAG_REGEX_, '');
479
+ };
480
+
481
+
482
+ /**
483
+ * Escapes HTML special characters in an HTML attribute value.
484
+ *
485
+ * @param {*} value The HTML to be escaped. May not be a string, but the
486
+ * value will be coerced to a string.
487
+ * @return {string} An escaped version of value.
488
+ */
489
+ soy.$$escapeHtmlAttribute = function(value) {
490
+ if (typeof value === 'object' && value &&
491
+ value.contentKind === soydata.SanitizedContentKind.HTML) {
492
+ return soy.esc.$$normalizeHtmlHelper(soy.$$stripHtmlTags(value.content));
493
+ }
494
+ return soy.esc.$$escapeHtmlHelper(value);
495
+ };
496
+
497
+
498
+ /**
499
+ * Escapes HTML special characters in a string including space and other
500
+ * characters that can end an unquoted HTML attribute value.
501
+ *
502
+ * @param {*} value The HTML to be escaped. May not be a string, but the
503
+ * value will be coerced to a string.
504
+ * @return {string} An escaped version of value.
505
+ */
506
+ soy.$$escapeHtmlAttributeNospace = function(value) {
507
+ if (typeof value === 'object' && value &&
508
+ value.contentKind === soydata.SanitizedContentKind.HTML) {
509
+ return soy.esc.$$normalizeHtmlNospaceHelper(
510
+ soy.$$stripHtmlTags(value.content));
511
+ }
512
+ return soy.esc.$$escapeHtmlNospaceHelper(value);
513
+ };
514
+
515
+
516
+ /**
517
+ * Filters out strings that cannot be a substring of a valid HTML attribute.
518
+ *
519
+ * @param {*} value The value to escape. May not be a string, but the value
520
+ * will be coerced to a string.
521
+ * @return {string} A valid HTML attribute name part or name/value pair.
522
+ * {@code "zSoyz"} if the input is invalid.
523
+ */
524
+ soy.$$filterHtmlAttribute = function(value) {
525
+ if (typeof value === 'object' && value &&
526
+ value.contentKind === soydata.SanitizedContentKind.HTML_ATTRIBUTE) {
527
+ return value.content.replace(/=([^"']*)$/, '="$1"');
528
+ }
529
+ return soy.esc.$$filterHtmlAttributeHelper(value);
530
+ };
531
+
532
+
533
+ /**
534
+ * Filters out strings that cannot be a substring of a valid HTML element name.
535
+ *
536
+ * @param {*} value The value to escape. May not be a string, but the value
537
+ * will be coerced to a string.
538
+ * @return {string} A valid HTML element name part.
539
+ * {@code "zSoyz"} if the input is invalid.
540
+ */
541
+ soy.$$filterHtmlElementName = function(value) {
542
+ return soy.esc.$$filterHtmlElementNameHelper(value);
543
+ };
544
+
545
+
546
+ /**
547
+ * Escapes characters in the value to make it valid content for a JS string
548
+ * literal.
549
+ *
550
+ * @param {*} value The value to escape. May not be a string, but the value
551
+ * will be coerced to a string.
552
+ * @return {string} An escaped version of value.
553
+ * @deprecated
554
+ */
555
+ soy.$$escapeJs = function(value) {
556
+ return soy.$$escapeJsString(value);
557
+ };
558
+
559
+
560
+ /**
561
+ * Escapes characters in the value to make it valid content for a JS string
562
+ * literal.
563
+ *
564
+ * @param {*} value The value to escape. May not be a string, but the value
565
+ * will be coerced to a string.
566
+ * @return {string} An escaped version of value.
567
+ */
568
+ soy.$$escapeJsString = function(value) {
569
+ if (typeof value === 'object' &&
570
+ value.contentKind === soydata.SanitizedContentKind.JS_STR_CHARS) {
571
+ return value.content;
572
+ }
573
+ return soy.esc.$$escapeJsStringHelper(value);
574
+ };
575
+
576
+
577
+ /**
578
+ * Encodes a value as a JavaScript literal.
579
+ *
580
+ * @param {*} value The value to escape. May not be a string, but the value
581
+ * will be coerced to a string.
582
+ * @return {string} A JavaScript code representation of the input.
583
+ */
584
+ soy.$$escapeJsValue = function(value) {
585
+ // We surround values with spaces so that they can't be interpolated into
586
+ // identifiers by accident.
587
+ // We could use parentheses but those might be interpreted as a function call.
588
+ if (value == null) { // Intentionally matches undefined.
589
+ // Java returns null from maps where there is no corresponding key while
590
+ // JS returns undefined.
591
+ // We always output null for compatibility with Java which does not have a
592
+ // distinct undefined value.
593
+ return ' null ';
594
+ }
595
+ switch (typeof value) {
596
+ case 'boolean': case 'number':
597
+ return ' ' + value + ' ';
598
+ default:
599
+ return "'" + soy.esc.$$escapeJsStringHelper(String(value)) + "'";
600
+ }
601
+ };
602
+
603
+
604
+ /**
605
+ * Escapes characters in the string to make it valid content for a JS regular
606
+ * expression literal.
607
+ *
608
+ * @param {*} value The value to escape. May not be a string, but the value
609
+ * will be coerced to a string.
610
+ * @return {string} An escaped version of value.
611
+ */
612
+ soy.$$escapeJsRegex = function(value) {
613
+ return soy.esc.$$escapeJsRegexHelper(value);
614
+ };
615
+
616
+
617
+ /**
618
+ * Matches all URI mark characters that conflict with HTML attribute delimiters
619
+ * or that cannot appear in a CSS uri.
620
+ * From <a href="http://www.w3.org/TR/CSS2/grammar.html">G.2: CSS grammar</a>
621
+ * <pre>
622
+ * url ([!#$%&*-~]|{nonascii}|{escape})*
623
+ * </pre>
624
+ *
625
+ * @type {RegExp}
626
+ * @private
627
+ */
628
+ soy.$$problematicUriMarks_ = /['()]/g;
629
+
630
+ /**
631
+ * @param {string} ch A single character in {@link soy.$$problematicUriMarks_}.
632
+ * @return {string}
633
+ * @private
634
+ */
635
+ soy.$$pctEncode_ = function(ch) {
636
+ return '%' + ch.charCodeAt(0).toString(16);
637
+ };
638
+
639
+ /**
640
+ * Escapes a string so that it can be safely included in a URI.
641
+ *
642
+ * @param {*} value The value to escape. May not be a string, but the value
643
+ * will be coerced to a string.
644
+ * @return {string} An escaped version of value.
645
+ */
646
+ soy.$$escapeUri = function(value) {
647
+ if (typeof value === 'object' &&
648
+ value.contentKind === soydata.SanitizedContentKind.URI) {
649
+ return soy.$$normalizeUri(value);
650
+ }
651
+ // Apostophes and parentheses are not matched by encodeURIComponent.
652
+ // They are technically special in URIs, but only appear in the obsolete mark
653
+ // production in Appendix D.2 of RFC 3986, so can be encoded without changing
654
+ // semantics.
655
+ var encoded = soy.esc.$$escapeUriHelper(value);
656
+ soy.$$problematicUriMarks_.lastIndex = 0;
657
+ if (soy.$$problematicUriMarks_.test(encoded)) {
658
+ return encoded.replace(soy.$$problematicUriMarks_, soy.$$pctEncode_);
659
+ }
660
+ return encoded;
661
+ };
662
+
663
+
664
+ /**
665
+ * Removes rough edges from a URI by escaping any raw HTML/JS string delimiters.
666
+ *
667
+ * @param {*} value The value to escape. May not be a string, but the value
668
+ * will be coerced to a string.
669
+ * @return {string} An escaped version of value.
670
+ */
671
+ soy.$$normalizeUri = function(value) {
672
+ return soy.esc.$$normalizeUriHelper(value);
673
+ };
674
+
675
+
676
+ /**
677
+ * Vets a URI's protocol and removes rough edges from a URI by escaping
678
+ * any raw HTML/JS string delimiters.
679
+ *
680
+ * @param {*} value The value to escape. May not be a string, but the value
681
+ * will be coerced to a string.
682
+ * @return {string} An escaped version of value.
683
+ */
684
+ soy.$$filterNormalizeUri = function(value) {
685
+ return soy.esc.$$filterNormalizeUriHelper(value);
686
+ };
687
+
688
+
689
+ /**
690
+ * Escapes a string so it can safely be included inside a quoted CSS string.
691
+ *
692
+ * @param {*} value The value to escape. May not be a string, but the value
693
+ * will be coerced to a string.
694
+ * @return {string} An escaped version of value.
695
+ */
696
+ soy.$$escapeCssString = function(value) {
697
+ return soy.esc.$$escapeCssStringHelper(value);
698
+ };
699
+
700
+
701
+ /**
702
+ * Encodes a value as a CSS identifier part, keyword, or quantity.
703
+ *
704
+ * @param {*} value The value to escape. May not be a string, but the value
705
+ * will be coerced to a string.
706
+ * @return {string} A safe CSS identifier part, keyword, or quanitity.
707
+ */
708
+ soy.$$filterCssValue = function(value) {
709
+ // Uses == to intentionally match null and undefined for Java compatibility.
710
+ if (value == null) {
711
+ return '';
712
+ }
713
+ return soy.esc.$$filterCssValueHelper(value);
714
+ };
715
+
716
+
717
+ // -----------------------------------------------------------------------------
718
+ // Basic directives/functions.
719
+
720
+
721
+ /**
722
+ * Converts \r\n, \r, and \n to <br>s
723
+ * @param {*} str The string in which to convert newlines.
724
+ * @return {string} A copy of {@code str} with converted newlines.
725
+ */
726
+ soy.$$changeNewlineToBr = function(str) {
727
+ return goog.string.newLineToBr(String(str), false);
728
+ };
729
+
730
+
731
+ /**
732
+ * Inserts word breaks ('wbr' tags) into a HTML string at a given interval. The
733
+ * counter is reset if a space is encountered. Word breaks aren't inserted into
734
+ * HTML tags or entities. Entites count towards the character count; HTML tags
735
+ * do not.
736
+ *
737
+ * @param {*} str The HTML string to insert word breaks into. Can be other
738
+ * types, but the value will be coerced to a string.
739
+ * @param {number} maxCharsBetweenWordBreaks Maximum number of non-space
740
+ * characters to allow before adding a word break.
741
+ * @return {string} The string including word breaks.
742
+ */
743
+ soy.$$insertWordBreaks = function(str, maxCharsBetweenWordBreaks) {
744
+ return goog.format.insertWordBreaks(String(str), maxCharsBetweenWordBreaks);
745
+ };
746
+
747
+
748
+ /**
749
+ * Truncates a string to a given max length (if it's currently longer),
750
+ * optionally adding ellipsis at the end.
751
+ *
752
+ * @param {*} str The string to truncate. Can be other types, but the value will
753
+ * be coerced to a string.
754
+ * @param {number} maxLen The maximum length of the string after truncation
755
+ * (including ellipsis, if applicable).
756
+ * @param {boolean} doAddEllipsis Whether to add ellipsis if the string needs
757
+ * truncation.
758
+ * @return {string} The string after truncation.
759
+ */
760
+ soy.$$truncate = function(str, maxLen, doAddEllipsis) {
761
+
762
+ str = String(str);
763
+ if (str.length <= maxLen) {
764
+ return str; // no need to truncate
765
+ }
766
+
767
+ // If doAddEllipsis, either reduce maxLen to compensate, or else if maxLen is
768
+ // too small, just turn off doAddEllipsis.
769
+ if (doAddEllipsis) {
770
+ if (maxLen > 3) {
771
+ maxLen -= 3;
772
+ } else {
773
+ doAddEllipsis = false;
774
+ }
775
+ }
776
+
777
+ // Make sure truncating at maxLen doesn't cut up a unicode surrogate pair.
778
+ if (soy.$$isHighSurrogate_(str.charAt(maxLen - 1)) &&
779
+ soy.$$isLowSurrogate_(str.charAt(maxLen))) {
780
+ maxLen -= 1;
781
+ }
782
+
783
+ // Truncate.
784
+ str = str.substring(0, maxLen);
785
+
786
+ // Add ellipsis.
787
+ if (doAddEllipsis) {
788
+ str += '...';
789
+ }
790
+
791
+ return str;
792
+ };
793
+
794
+ /**
795
+ * Private helper for $$truncate() to check whether a char is a high surrogate.
796
+ * @param {string} ch The char to check.
797
+ * @return {boolean} Whether the given char is a unicode high surrogate.
798
+ * @private
799
+ */
800
+ soy.$$isHighSurrogate_ = function(ch) {
801
+ return 0xD800 <= ch && ch <= 0xDBFF;
802
+ };
803
+
804
+ /**
805
+ * Private helper for $$truncate() to check whether a char is a low surrogate.
806
+ * @param {string} ch The char to check.
807
+ * @return {boolean} Whether the given char is a unicode low surrogate.
808
+ * @private
809
+ */
810
+ soy.$$isLowSurrogate_ = function(ch) {
811
+ return 0xDC00 <= ch && ch <= 0xDFFF;
812
+ };
813
+
814
+
815
+ // -----------------------------------------------------------------------------
816
+ // Bidi directives/functions.
817
+
818
+
819
+ /**
820
+ * Cache of bidi formatter by context directionality, so we don't keep on
821
+ * creating new objects.
822
+ * @type {!Object.<!goog.i18n.BidiFormatter>}
823
+ * @private
824
+ */
825
+ soy.$$bidiFormatterCache_ = {};
826
+
827
+
828
+ /**
829
+ * Returns cached bidi formatter for bidiGlobalDir, or creates a new one.
830
+ * @param {number} bidiGlobalDir The global directionality context: 1 if ltr, -1
831
+ * if rtl, 0 if unknown.
832
+ * @return {goog.i18n.BidiFormatter} A formatter for bidiGlobalDir.
833
+ * @private
834
+ */
835
+ soy.$$getBidiFormatterInstance_ = function(bidiGlobalDir) {
836
+ return soy.$$bidiFormatterCache_[bidiGlobalDir] ||
837
+ (soy.$$bidiFormatterCache_[bidiGlobalDir] =
838
+ new goog.i18n.BidiFormatter(bidiGlobalDir));
839
+ };
840
+
841
+
842
+ /**
843
+ * Estimate the overall directionality of text. If opt_isHtml, makes sure to
844
+ * ignore the LTR nature of the mark-up and escapes in text, making the logic
845
+ * suitable for HTML and HTML-escaped text.
846
+ * @param {string} text The text whose directionality is to be estimated.
847
+ * @param {boolean=} opt_isHtml Whether text is HTML/HTML-escaped.
848
+ * Default: false.
849
+ * @return {number} 1 if text is LTR, -1 if it is RTL, and 0 if it is neutral.
850
+ */
851
+ soy.$$bidiTextDir = function(text, opt_isHtml) {
852
+ if (!text) {
853
+ return 0;
854
+ }
855
+ return goog.i18n.bidi.detectRtlDirectionality(text, opt_isHtml) ? -1 : 1;
856
+ };
857
+
858
+
859
+ /**
860
+ * Returns "dir=ltr" or "dir=rtl", depending on text's estimated
861
+ * directionality, if it is not the same as bidiGlobalDir.
862
+ * Otherwise, returns the empty string.
863
+ * If opt_isHtml, makes sure to ignore the LTR nature of the mark-up and escapes
864
+ * in text, making the logic suitable for HTML and HTML-escaped text.
865
+ * @param {number} bidiGlobalDir The global directionality context: 1 if ltr, -1
866
+ * if rtl, 0 if unknown.
867
+ * @param {string} text The text whose directionality is to be estimated.
868
+ * @param {boolean=} opt_isHtml Whether text is HTML/HTML-escaped.
869
+ * Default: false.
870
+ * @return {soydata.SanitizedHtmlAttribute} "dir=rtl" for RTL text in non-RTL
871
+ * context; "dir=ltr" for LTR text in non-LTR context;
872
+ * else, the empty string.
873
+ */
874
+ soy.$$bidiDirAttr = function(bidiGlobalDir, text, opt_isHtml) {
875
+ return new soydata.SanitizedHtmlAttribute(
876
+ soy.$$getBidiFormatterInstance_(bidiGlobalDir).dirAttr(text, opt_isHtml));
877
+ };
878
+
879
+
880
+ /**
881
+ * Returns a Unicode BiDi mark matching bidiGlobalDir (LRM or RLM) if the
882
+ * directionality or the exit directionality of text are opposite to
883
+ * bidiGlobalDir. Otherwise returns the empty string.
884
+ * If opt_isHtml, makes sure to ignore the LTR nature of the mark-up and escapes
885
+ * in text, making the logic suitable for HTML and HTML-escaped text.
886
+ * @param {number} bidiGlobalDir The global directionality context: 1 if ltr, -1
887
+ * if rtl, 0 if unknown.
888
+ * @param {string} text The text whose directionality is to be estimated.
889
+ * @param {boolean=} opt_isHtml Whether text is HTML/HTML-escaped.
890
+ * Default: false.
891
+ * @return {string} A Unicode bidi mark matching bidiGlobalDir, or the empty
892
+ * string when text's overall and exit directionalities both match
893
+ * bidiGlobalDir, or bidiGlobalDir is 0 (unknown).
894
+ */
895
+ soy.$$bidiMarkAfter = function(bidiGlobalDir, text, opt_isHtml) {
896
+ var formatter = soy.$$getBidiFormatterInstance_(bidiGlobalDir);
897
+ return formatter.markAfter(text, opt_isHtml);
898
+ };
899
+
900
+
901
+ /**
902
+ * Returns str wrapped in a <span dir=ltr|rtl> according to its directionality -
903
+ * but only if that is neither neutral nor the same as the global context.
904
+ * Otherwise, returns str unchanged.
905
+ * Always treats str as HTML/HTML-escaped, i.e. ignores mark-up and escapes when
906
+ * estimating str's directionality.
907
+ * @param {number} bidiGlobalDir The global directionality context: 1 if ltr, -1
908
+ * if rtl, 0 if unknown.
909
+ * @param {*} str The string to be wrapped. Can be other types, but the value
910
+ * will be coerced to a string.
911
+ * @return {string} The wrapped string.
912
+ */
913
+ soy.$$bidiSpanWrap = function(bidiGlobalDir, str) {
914
+ var formatter = soy.$$getBidiFormatterInstance_(bidiGlobalDir);
915
+ return formatter.spanWrap(str + '', true);
916
+ };
917
+
918
+
919
+ /**
920
+ * Returns str wrapped in Unicode BiDi formatting characters according to its
921
+ * directionality, i.e. either LRE or RLE at the beginning and PDF at the end -
922
+ * but only if str's directionality is neither neutral nor the same as the
923
+ * global context. Otherwise, returns str unchanged.
924
+ * Always treats str as HTML/HTML-escaped, i.e. ignores mark-up and escapes when
925
+ * estimating str's directionality.
926
+ * @param {number} bidiGlobalDir The global directionality context: 1 if ltr, -1
927
+ * if rtl, 0 if unknown.
928
+ * @param {*} str The string to be wrapped. Can be other types, but the value
929
+ * will be coerced to a string.
930
+ * @return {string} The wrapped string.
931
+ */
932
+ soy.$$bidiUnicodeWrap = function(bidiGlobalDir, str) {
933
+ var formatter = soy.$$getBidiFormatterInstance_(bidiGlobalDir);
934
+ return formatter.unicodeWrap(str + '', true);
935
+ };
936
+
937
+
938
+ // -----------------------------------------------------------------------------
939
+ // Generated code.
940
+
941
+
942
+
943
+
944
+ // START GENERATED CODE FOR ESCAPERS.
945
+
946
+ /**
947
+ * @type {function (*) : string}
948
+ */
949
+ soy.esc.$$escapeUriHelper = function(v) {
950
+ return goog.string.urlEncode(String(v));
951
+ };
952
+
953
+ /**
954
+ * Maps charcters to the escaped versions for the named escape directives.
955
+ * @type {Object.<string, string>}
956
+ * @private
957
+ */
958
+ soy.esc.$$ESCAPE_MAP_FOR_ESCAPE_HTML__AND__NORMALIZE_HTML__AND__ESCAPE_HTML_NOSPACE__AND__NORMALIZE_HTML_NOSPACE_ = {
959
+ '\x00': '\x26#0;',
960
+ '\x22': '\x26quot;',
961
+ '\x26': '\x26amp;',
962
+ '\x27': '\x26#39;',
963
+ '\x3c': '\x26lt;',
964
+ '\x3e': '\x26gt;',
965
+ '\x09': '\x26#9;',
966
+ '\x0a': '\x26#10;',
967
+ '\x0b': '\x26#11;',
968
+ '\x0c': '\x26#12;',
969
+ '\x0d': '\x26#13;',
970
+ ' ': '\x26#32;',
971
+ '-': '\x26#45;',
972
+ '\/': '\x26#47;',
973
+ '\x3d': '\x26#61;',
974
+ '`': '\x26#96;',
975
+ '\x85': '\x26#133;',
976
+ '\xa0': '\x26#160;',
977
+ '\u2028': '\x26#8232;',
978
+ '\u2029': '\x26#8233;'
979
+ };
980
+
981
+ /**
982
+ * A function that can be used with String.replace..
983
+ * @param {string} ch A single character matched by a compatible matcher.
984
+ * @return {string} A token in the output language.
985
+ * @private
986
+ */
987
+ soy.esc.$$REPLACER_FOR_ESCAPE_HTML__AND__NORMALIZE_HTML__AND__ESCAPE_HTML_NOSPACE__AND__NORMALIZE_HTML_NOSPACE_ = function(ch) {
988
+ return soy.esc.$$ESCAPE_MAP_FOR_ESCAPE_HTML__AND__NORMALIZE_HTML__AND__ESCAPE_HTML_NOSPACE__AND__NORMALIZE_HTML_NOSPACE_[ch];
989
+ };
990
+
991
+ /**
992
+ * Maps charcters to the escaped versions for the named escape directives.
993
+ * @type {Object.<string, string>}
994
+ * @private
995
+ */
996
+ soy.esc.$$ESCAPE_MAP_FOR_ESCAPE_JS_STRING__AND__ESCAPE_JS_REGEX_ = {
997
+ '\x00': '\\x00',
998
+ '\x08': '\\x08',
999
+ '\x09': '\\t',
1000
+ '\x0a': '\\n',
1001
+ '\x0b': '\\x0b',
1002
+ '\x0c': '\\f',
1003
+ '\x0d': '\\r',
1004
+ '\x22': '\\x22',
1005
+ '\x26': '\\x26',
1006
+ '\x27': '\\x27',
1007
+ '\/': '\\\/',
1008
+ '\x3c': '\\x3c',
1009
+ '\x3d': '\\x3d',
1010
+ '\x3e': '\\x3e',
1011
+ '\\': '\\\\',
1012
+ '\x85': '\\x85',
1013
+ '\u2028': '\\u2028',
1014
+ '\u2029': '\\u2029',
1015
+ '$': '\\x24',
1016
+ '(': '\\x28',
1017
+ ')': '\\x29',
1018
+ '*': '\\x2a',
1019
+ '+': '\\x2b',
1020
+ ',': '\\x2c',
1021
+ '-': '\\x2d',
1022
+ '.': '\\x2e',
1023
+ ':': '\\x3a',
1024
+ '?': '\\x3f',
1025
+ '[': '\\x5b',
1026
+ ']': '\\x5d',
1027
+ '^': '\\x5e',
1028
+ '{': '\\x7b',
1029
+ '|': '\\x7c',
1030
+ '}': '\\x7d'
1031
+ };
1032
+
1033
+ /**
1034
+ * A function that can be used with String.replace..
1035
+ * @param {string} ch A single character matched by a compatible matcher.
1036
+ * @return {string} A token in the output language.
1037
+ * @private
1038
+ */
1039
+ soy.esc.$$REPLACER_FOR_ESCAPE_JS_STRING__AND__ESCAPE_JS_REGEX_ = function(ch) {
1040
+ return soy.esc.$$ESCAPE_MAP_FOR_ESCAPE_JS_STRING__AND__ESCAPE_JS_REGEX_[ch];
1041
+ };
1042
+
1043
+ /**
1044
+ * Maps charcters to the escaped versions for the named escape directives.
1045
+ * @type {Object.<string, string>}
1046
+ * @private
1047
+ */
1048
+ soy.esc.$$ESCAPE_MAP_FOR_ESCAPE_CSS_STRING_ = {
1049
+ '\x00': '\\0 ',
1050
+ '\x08': '\\8 ',
1051
+ '\x09': '\\9 ',
1052
+ '\x0a': '\\a ',
1053
+ '\x0b': '\\b ',
1054
+ '\x0c': '\\c ',
1055
+ '\x0d': '\\d ',
1056
+ '\x22': '\\22 ',
1057
+ '\x26': '\\26 ',
1058
+ '\x27': '\\27 ',
1059
+ '(': '\\28 ',
1060
+ ')': '\\29 ',
1061
+ '*': '\\2a ',
1062
+ '\/': '\\2f ',
1063
+ ':': '\\3a ',
1064
+ ';': '\\3b ',
1065
+ '\x3c': '\\3c ',
1066
+ '\x3d': '\\3d ',
1067
+ '\x3e': '\\3e ',
1068
+ '@': '\\40 ',
1069
+ '\\': '\\5c ',
1070
+ '{': '\\7b ',
1071
+ '}': '\\7d ',
1072
+ '\x85': '\\85 ',
1073
+ '\xa0': '\\a0 ',
1074
+ '\u2028': '\\2028 ',
1075
+ '\u2029': '\\2029 '
1076
+ };
1077
+
1078
+ /**
1079
+ * A function that can be used with String.replace..
1080
+ * @param {string} ch A single character matched by a compatible matcher.
1081
+ * @return {string} A token in the output language.
1082
+ * @private
1083
+ */
1084
+ soy.esc.$$REPLACER_FOR_ESCAPE_CSS_STRING_ = function(ch) {
1085
+ return soy.esc.$$ESCAPE_MAP_FOR_ESCAPE_CSS_STRING_[ch];
1086
+ };
1087
+
1088
+ /**
1089
+ * Maps charcters to the escaped versions for the named escape directives.
1090
+ * @type {Object.<string, string>}
1091
+ * @private
1092
+ */
1093
+ soy.esc.$$ESCAPE_MAP_FOR_NORMALIZE_URI__AND__FILTER_NORMALIZE_URI_ = {
1094
+ '\x00': '%00',
1095
+ '\x01': '%01',
1096
+ '\x02': '%02',
1097
+ '\x03': '%03',
1098
+ '\x04': '%04',
1099
+ '\x05': '%05',
1100
+ '\x06': '%06',
1101
+ '\x07': '%07',
1102
+ '\x08': '%08',
1103
+ '\x09': '%09',
1104
+ '\x0a': '%0A',
1105
+ '\x0b': '%0B',
1106
+ '\x0c': '%0C',
1107
+ '\x0d': '%0D',
1108
+ '\x0e': '%0E',
1109
+ '\x0f': '%0F',
1110
+ '\x10': '%10',
1111
+ '\x11': '%11',
1112
+ '\x12': '%12',
1113
+ '\x13': '%13',
1114
+ '\x14': '%14',
1115
+ '\x15': '%15',
1116
+ '\x16': '%16',
1117
+ '\x17': '%17',
1118
+ '\x18': '%18',
1119
+ '\x19': '%19',
1120
+ '\x1a': '%1A',
1121
+ '\x1b': '%1B',
1122
+ '\x1c': '%1C',
1123
+ '\x1d': '%1D',
1124
+ '\x1e': '%1E',
1125
+ '\x1f': '%1F',
1126
+ ' ': '%20',
1127
+ '\x22': '%22',
1128
+ '\x27': '%27',
1129
+ '(': '%28',
1130
+ ')': '%29',
1131
+ '\x3c': '%3C',
1132
+ '\x3e': '%3E',
1133
+ '\\': '%5C',
1134
+ '{': '%7B',
1135
+ '}': '%7D',
1136
+ '\x7f': '%7F',
1137
+ '\x85': '%C2%85',
1138
+ '\xa0': '%C2%A0',
1139
+ '\u2028': '%E2%80%A8',
1140
+ '\u2029': '%E2%80%A9',
1141
+ '\uff01': '%EF%BC%81',
1142
+ '\uff03': '%EF%BC%83',
1143
+ '\uff04': '%EF%BC%84',
1144
+ '\uff06': '%EF%BC%86',
1145
+ '\uff07': '%EF%BC%87',
1146
+ '\uff08': '%EF%BC%88',
1147
+ '\uff09': '%EF%BC%89',
1148
+ '\uff0a': '%EF%BC%8A',
1149
+ '\uff0b': '%EF%BC%8B',
1150
+ '\uff0c': '%EF%BC%8C',
1151
+ '\uff0f': '%EF%BC%8F',
1152
+ '\uff1a': '%EF%BC%9A',
1153
+ '\uff1b': '%EF%BC%9B',
1154
+ '\uff1d': '%EF%BC%9D',
1155
+ '\uff1f': '%EF%BC%9F',
1156
+ '\uff20': '%EF%BC%A0',
1157
+ '\uff3b': '%EF%BC%BB',
1158
+ '\uff3d': '%EF%BC%BD'
1159
+ };
1160
+
1161
+ /**
1162
+ * A function that can be used with String.replace..
1163
+ * @param {string} ch A single character matched by a compatible matcher.
1164
+ * @return {string} A token in the output language.
1165
+ * @private
1166
+ */
1167
+ soy.esc.$$REPLACER_FOR_NORMALIZE_URI__AND__FILTER_NORMALIZE_URI_ = function(ch) {
1168
+ return soy.esc.$$ESCAPE_MAP_FOR_NORMALIZE_URI__AND__FILTER_NORMALIZE_URI_[ch];
1169
+ };
1170
+
1171
+ /**
1172
+ * Matches characters that need to be escaped for the named directives.
1173
+ * @type RegExp
1174
+ * @private
1175
+ */
1176
+ soy.esc.$$MATCHER_FOR_ESCAPE_HTML_ = /[\x00\x22\x26\x27\x3c\x3e]/g;
1177
+
1178
+ /**
1179
+ * Matches characters that need to be escaped for the named directives.
1180
+ * @type RegExp
1181
+ * @private
1182
+ */
1183
+ soy.esc.$$MATCHER_FOR_NORMALIZE_HTML_ = /[\x00\x22\x27\x3c\x3e]/g;
1184
+
1185
+ /**
1186
+ * Matches characters that need to be escaped for the named directives.
1187
+ * @type RegExp
1188
+ * @private
1189
+ */
1190
+ soy.esc.$$MATCHER_FOR_ESCAPE_HTML_NOSPACE_ = /[\x00\x09-\x0d \x22\x26\x27\x2d\/\x3c-\x3e`\x85\xa0\u2028\u2029]/g;
1191
+
1192
+ /**
1193
+ * Matches characters that need to be escaped for the named directives.
1194
+ * @type RegExp
1195
+ * @private
1196
+ */
1197
+ soy.esc.$$MATCHER_FOR_NORMALIZE_HTML_NOSPACE_ = /[\x00\x09-\x0d \x22\x27\x2d\/\x3c-\x3e`\x85\xa0\u2028\u2029]/g;
1198
+
1199
+ /**
1200
+ * Matches characters that need to be escaped for the named directives.
1201
+ * @type RegExp
1202
+ * @private
1203
+ */
1204
+ soy.esc.$$MATCHER_FOR_ESCAPE_JS_STRING_ = /[\x00\x08-\x0d\x22\x26\x27\/\x3c-\x3e\\\x85\u2028\u2029]/g;
1205
+
1206
+ /**
1207
+ * Matches characters that need to be escaped for the named directives.
1208
+ * @type RegExp
1209
+ * @private
1210
+ */
1211
+ soy.esc.$$MATCHER_FOR_ESCAPE_JS_REGEX_ = /[\x00\x08-\x0d\x22\x24\x26-\/\x3a\x3c-\x3f\x5b-\x5e\x7b-\x7d\x85\u2028\u2029]/g;
1212
+
1213
+ /**
1214
+ * Matches characters that need to be escaped for the named directives.
1215
+ * @type RegExp
1216
+ * @private
1217
+ */
1218
+ soy.esc.$$MATCHER_FOR_ESCAPE_CSS_STRING_ = /[\x00\x08-\x0d\x22\x26-\x2a\/\x3a-\x3e@\\\x7b\x7d\x85\xa0\u2028\u2029]/g;
1219
+
1220
+ /**
1221
+ * Matches characters that need to be escaped for the named directives.
1222
+ * @type RegExp
1223
+ * @private
1224
+ */
1225
+ soy.esc.$$MATCHER_FOR_NORMALIZE_URI__AND__FILTER_NORMALIZE_URI_ = /[\x00- \x22\x27-\x29\x3c\x3e\\\x7b\x7d\x7f\x85\xa0\u2028\u2029\uff01\uff03\uff04\uff06-\uff0c\uff0f\uff1a\uff1b\uff1d\uff1f\uff20\uff3b\uff3d]/g;
1226
+
1227
+ /**
1228
+ * A pattern that vets values produced by the named directives.
1229
+ * @type RegExp
1230
+ * @private
1231
+ */
1232
+ soy.esc.$$FILTER_FOR_FILTER_CSS_VALUE_ = /^(?!-*(?:expression|(?:moz-)?binding))(?:[.#]?-?(?:[_a-z0-9-]+)(?:-[_a-z0-9-]+)*-?|-?(?:[0-9]+(?:\.[0-9]*)?|\.[0-9]+)(?:[a-z]{1,2}|%)?|!important|)$/i;
1233
+
1234
+ /**
1235
+ * A pattern that vets values produced by the named directives.
1236
+ * @type RegExp
1237
+ * @private
1238
+ */
1239
+ soy.esc.$$FILTER_FOR_FILTER_NORMALIZE_URI_ = /^(?:(?:https?|mailto):|[^&:\/?#]*(?:[\/?#]|$))/i;
1240
+
1241
+ /**
1242
+ * A pattern that vets values produced by the named directives.
1243
+ * @type RegExp
1244
+ * @private
1245
+ */
1246
+ soy.esc.$$FILTER_FOR_FILTER_HTML_ATTRIBUTE_ = /^(?!style|on|action|archive|background|cite|classid|codebase|data|dsync|href|longdesc|src|usemap)(?:[a-z0-9_$:-]*)$/i;
1247
+
1248
+ /**
1249
+ * A pattern that vets values produced by the named directives.
1250
+ * @type RegExp
1251
+ * @private
1252
+ */
1253
+ soy.esc.$$FILTER_FOR_FILTER_HTML_ELEMENT_NAME_ = /^(?!script|style|title|textarea|xmp|no)[a-z0-9_$:-]*$/i;
1254
+
1255
+ /**
1256
+ * A helper for the Soy directive |escapeHtml
1257
+ * @param {*} value Can be of any type but will be coerced to a string.
1258
+ * @return {string} The escaped text.
1259
+ */
1260
+ soy.esc.$$escapeHtmlHelper = function(value) {
1261
+ var str = String(value);
1262
+ return str.replace(
1263
+ soy.esc.$$MATCHER_FOR_ESCAPE_HTML_,
1264
+ soy.esc.$$REPLACER_FOR_ESCAPE_HTML__AND__NORMALIZE_HTML__AND__ESCAPE_HTML_NOSPACE__AND__NORMALIZE_HTML_NOSPACE_);
1265
+ };
1266
+
1267
+ /**
1268
+ * A helper for the Soy directive |normalizeHtml
1269
+ * @param {*} value Can be of any type but will be coerced to a string.
1270
+ * @return {string} The escaped text.
1271
+ */
1272
+ soy.esc.$$normalizeHtmlHelper = function(value) {
1273
+ var str = String(value);
1274
+ return str.replace(
1275
+ soy.esc.$$MATCHER_FOR_NORMALIZE_HTML_,
1276
+ soy.esc.$$REPLACER_FOR_ESCAPE_HTML__AND__NORMALIZE_HTML__AND__ESCAPE_HTML_NOSPACE__AND__NORMALIZE_HTML_NOSPACE_);
1277
+ };
1278
+
1279
+ /**
1280
+ * A helper for the Soy directive |escapeHtmlNospace
1281
+ * @param {*} value Can be of any type but will be coerced to a string.
1282
+ * @return {string} The escaped text.
1283
+ */
1284
+ soy.esc.$$escapeHtmlNospaceHelper = function(value) {
1285
+ var str = String(value);
1286
+ return str.replace(
1287
+ soy.esc.$$MATCHER_FOR_ESCAPE_HTML_NOSPACE_,
1288
+ soy.esc.$$REPLACER_FOR_ESCAPE_HTML__AND__NORMALIZE_HTML__AND__ESCAPE_HTML_NOSPACE__AND__NORMALIZE_HTML_NOSPACE_);
1289
+ };
1290
+
1291
+ /**
1292
+ * A helper for the Soy directive |normalizeHtmlNospace
1293
+ * @param {*} value Can be of any type but will be coerced to a string.
1294
+ * @return {string} The escaped text.
1295
+ */
1296
+ soy.esc.$$normalizeHtmlNospaceHelper = function(value) {
1297
+ var str = String(value);
1298
+ return str.replace(
1299
+ soy.esc.$$MATCHER_FOR_NORMALIZE_HTML_NOSPACE_,
1300
+ soy.esc.$$REPLACER_FOR_ESCAPE_HTML__AND__NORMALIZE_HTML__AND__ESCAPE_HTML_NOSPACE__AND__NORMALIZE_HTML_NOSPACE_);
1301
+ };
1302
+
1303
+ /**
1304
+ * A helper for the Soy directive |escapeJsString
1305
+ * @param {*} value Can be of any type but will be coerced to a string.
1306
+ * @return {string} The escaped text.
1307
+ */
1308
+ soy.esc.$$escapeJsStringHelper = function(value) {
1309
+ var str = String(value);
1310
+ return str.replace(
1311
+ soy.esc.$$MATCHER_FOR_ESCAPE_JS_STRING_,
1312
+ soy.esc.$$REPLACER_FOR_ESCAPE_JS_STRING__AND__ESCAPE_JS_REGEX_);
1313
+ };
1314
+
1315
+ /**
1316
+ * A helper for the Soy directive |escapeJsRegex
1317
+ * @param {*} value Can be of any type but will be coerced to a string.
1318
+ * @return {string} The escaped text.
1319
+ */
1320
+ soy.esc.$$escapeJsRegexHelper = function(value) {
1321
+ var str = String(value);
1322
+ return str.replace(
1323
+ soy.esc.$$MATCHER_FOR_ESCAPE_JS_REGEX_,
1324
+ soy.esc.$$REPLACER_FOR_ESCAPE_JS_STRING__AND__ESCAPE_JS_REGEX_);
1325
+ };
1326
+
1327
+ /**
1328
+ * A helper for the Soy directive |escapeCssString
1329
+ * @param {*} value Can be of any type but will be coerced to a string.
1330
+ * @return {string} The escaped text.
1331
+ */
1332
+ soy.esc.$$escapeCssStringHelper = function(value) {
1333
+ var str = String(value);
1334
+ return str.replace(
1335
+ soy.esc.$$MATCHER_FOR_ESCAPE_CSS_STRING_,
1336
+ soy.esc.$$REPLACER_FOR_ESCAPE_CSS_STRING_);
1337
+ };
1338
+
1339
+ /**
1340
+ * A helper for the Soy directive |filterCssValue
1341
+ * @param {*} value Can be of any type but will be coerced to a string.
1342
+ * @return {string} The escaped text.
1343
+ */
1344
+ soy.esc.$$filterCssValueHelper = function(value) {
1345
+ var str = String(value);
1346
+ if (!soy.esc.$$FILTER_FOR_FILTER_CSS_VALUE_.test(str)) {
1347
+ goog.asserts.fail('Bad value `%s` for |filterCssValue', [str]);
1348
+ return 'zSoyz';
1349
+ }
1350
+ return str;
1351
+ };
1352
+
1353
+ /**
1354
+ * A helper for the Soy directive |normalizeUri
1355
+ * @param {*} value Can be of any type but will be coerced to a string.
1356
+ * @return {string} The escaped text.
1357
+ */
1358
+ soy.esc.$$normalizeUriHelper = function(value) {
1359
+ var str = String(value);
1360
+ return str.replace(
1361
+ soy.esc.$$MATCHER_FOR_NORMALIZE_URI__AND__FILTER_NORMALIZE_URI_,
1362
+ soy.esc.$$REPLACER_FOR_NORMALIZE_URI__AND__FILTER_NORMALIZE_URI_);
1363
+ };
1364
+
1365
+ /**
1366
+ * A helper for the Soy directive |filterNormalizeUri
1367
+ * @param {*} value Can be of any type but will be coerced to a string.
1368
+ * @return {string} The escaped text.
1369
+ */
1370
+ soy.esc.$$filterNormalizeUriHelper = function(value) {
1371
+ var str = String(value);
1372
+ if (!soy.esc.$$FILTER_FOR_FILTER_NORMALIZE_URI_.test(str)) {
1373
+ goog.asserts.fail('Bad value `%s` for |filterNormalizeUri', [str]);
1374
+ return 'zSoyz';
1375
+ }
1376
+ return str.replace(
1377
+ soy.esc.$$MATCHER_FOR_NORMALIZE_URI__AND__FILTER_NORMALIZE_URI_,
1378
+ soy.esc.$$REPLACER_FOR_NORMALIZE_URI__AND__FILTER_NORMALIZE_URI_);
1379
+ };
1380
+
1381
+ /**
1382
+ * A helper for the Soy directive |filterHtmlAttribute
1383
+ * @param {*} value Can be of any type but will be coerced to a string.
1384
+ * @return {string} The escaped text.
1385
+ */
1386
+ soy.esc.$$filterHtmlAttributeHelper = function(value) {
1387
+ var str = String(value);
1388
+ if (!soy.esc.$$FILTER_FOR_FILTER_HTML_ATTRIBUTE_.test(str)) {
1389
+ goog.asserts.fail('Bad value `%s` for |filterHtmlAttribute', [str]);
1390
+ return 'zSoyz';
1391
+ }
1392
+ return str;
1393
+ };
1394
+
1395
+ /**
1396
+ * A helper for the Soy directive |filterHtmlElementName
1397
+ * @param {*} value Can be of any type but will be coerced to a string.
1398
+ * @return {string} The escaped text.
1399
+ */
1400
+ soy.esc.$$filterHtmlElementNameHelper = function(value) {
1401
+ var str = String(value);
1402
+ if (!soy.esc.$$FILTER_FOR_FILTER_HTML_ELEMENT_NAME_.test(str)) {
1403
+ goog.asserts.fail('Bad value `%s` for |filterHtmlElementName', [str]);
1404
+ return 'zSoyz';
1405
+ }
1406
+ return str;
1407
+ };
1408
+
1409
+ /**
1410
+ * Matches all tags, HTML comments, and DOCTYPEs in tag soup HTML.
1411
+ *
1412
+ * @type {RegExp}
1413
+ * @private
1414
+ */
1415
+ soy.esc.$$HTML_TAG_REGEX_ = /<(?:!|\/?[a-zA-Z])(?:[^>'"]|"[^"]*"|'[^']*')*>/g;
1416
+
1417
+ // END GENERATED CODE