Revision: 5702
Author: [email protected]
Date: Wed Oct 15 18:28:07 2014 UTC
Log: Work around Firefox 33 regexp performance bug in CSS lexer.
https://codereview.appspot.com/157080044
In Firefox 33, regexp operations on strings which can be represented
as Latin-1 characters only may be very slow or hung. Work around
this for our CSS lexer by inserting a funny character temporarily.
This change is based on a patch provided by James Keane, with
additional explanatory text and rearrangement of the existing code.
The browser bug is expected to be fixed in Firefox 34.
https://code.google.com/p/google-caja/issues/detail?id=1941
https://bugzilla.mozilla.org/show_bug.cgi?id=1081175
[email protected]
https://code.google.com/p/google-caja/source/detail?r=5702
Modified:
/trunk/src/com/google/caja/plugin/csslexer.js
=======================================
--- /trunk/src/com/google/caja/plugin/csslexer.js Mon Sep 9 23:02:35 2013
UTC
+++ /trunk/src/com/google/caja/plugin/csslexer.js Wed Oct 15 18:28:07 2014
UTC
@@ -225,9 +225,18 @@
* delimiters and to not otherwise contain double quotes.
*/
lexCss = function (cssText) {
- cssText = '' + cssText;
- var tokens = cssText.replace(/\r\n?/g, '\n') // Normalize CRLF & CR
to LF.
- .match(CSS_TOKEN) || [];
+ // Stringify input. Additionally, insert and remove a non-latin1
character
+ // to force Firefox 33 to switch to a wide string representation,
avoiding
+ // a performance bug. This workaround should become unnecessary after
+ // Firefox 34. https://bugzilla.mozilla.org/show_bug.cgi?id=1081175
+ // https://code.google.com/p/google-caja/issues/detail?id=1941
+ cssText = ('\uffff' + cssText).replace(/^\uffff/, '');
+
+ // // Normalize CRLF & CR to LF.
+ cssText = cssText.replace(/\r\n?/g, '\n');
+
+ // Tokenize.
+ var tokens = cssText.match(CSS_TOKEN) || [];
var j = 0;
var last = ' ';
for (var i = 0, n = tokens.length; i < n; ++i) {
--
---
You received this message because you are subscribed to the Google Groups "Google Caja Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.