diff options
Diffstat (limited to 'mcs/class/System.Web.Extensions/System.Web.Handlers/ScriptResourceHandler.cs')
-rw-r--r-- | mcs/class/System.Web.Extensions/System.Web.Handlers/ScriptResourceHandler.cs | 44 |
1 files changed, 38 insertions, 6 deletions
diff --git a/mcs/class/System.Web.Extensions/System.Web.Handlers/ScriptResourceHandler.cs b/mcs/class/System.Web.Extensions/System.Web.Handlers/ScriptResourceHandler.cs index 34cf597043d..373d9661fb4 100644 --- a/mcs/class/System.Web.Extensions/System.Web.Handlers/ScriptResourceHandler.cs +++ b/mcs/class/System.Web.Extensions/System.Web.Handlers/ScriptResourceHandler.cs @@ -51,12 +51,44 @@ namespace System.Web.Handlers #endregion
- // TODO: optimize
- static string GetScriptStringLiteral (string value) {
- string s = value;
- s = s.Replace ("\\", "\\\\");
- s = s.Replace ("\"", "\\\"");
- return "\"" + s + "\"";
+ // TODO: add value cache?
+ static string GetScriptStringLiteral (string value)
+ {
+ if (String.IsNullOrEmpty (value))
+ return "\"" + value + "\"";
+
+ var sb = new StringBuilder ("\"");
+ for (int i = 0; i < value.Length; i++) {
+ char ch = value [i];
+ switch (ch) {
+ case '\'':
+ sb.Append ("\\u0027");
+ break;
+
+ case '"':
+ sb.Append ("\\\"");
+ break;
+
+ case '\\':
+ sb.Append ("\\\\");
+ break;
+
+ case '\n':
+ sb.Append ("\\n");
+ break;
+
+ case '\r':
+ sb.Append ("\\r");
+ break;
+
+ default:
+ sb.Append (ch);
+ break;
+ }
+ }
+ sb.Append ("\"");
+
+ return sb.ToString ();
}
class ResourceKey
|