Index: main/trunk/greenstone2/runtime-src/src/recpt/receptionist.cpp
===================================================================
--- main/trunk/greenstone2/runtime-src/src/recpt/receptionist.cpp	(revision 28888)
+++ main/trunk/greenstone2/runtime-src/src/recpt/receptionist.cpp	(revision 28898)
@@ -1532,5 +1532,5 @@
     text_t attrsafe = encodeForHTMLAttr(macrovalue);
     text_t urlsafe = encodeForURL(macrovalue);
-    text_t jssafe = encodeForJavascript(macrovalue);
+    text_t jssafe = encodeForJavascript(macrovalue); // with default setting will return \\x and \\u for macro files
     text_t csssafe = encodeForCSS(macrovalue);
 
Index: main/trunk/greenstone2/runtime-src/src/recpt/securitytools.cpp
===================================================================
--- main/trunk/greenstone2/runtime-src/src/recpt/securitytools.cpp	(revision 28888)
+++ main/trunk/greenstone2/runtime-src/src/recpt/securitytools.cpp	(revision 28898)
@@ -125,14 +125,15 @@
 }
 
-text_t encodeForJavascript(const text_t& in, const text_t& immuneChars) {
-  text_t out;
-  text_t::const_iterator here = in.begin();
-  text_t::const_iterator end = in.end();
-  while (here != end) {
-    out += encodeForJavascript(immuneChars, *here); // IMMUNE_JAVASCRIPT by default
-    ++here;
-  }
-  return out;
-}
+text_t encodeForJavascript(const text_t& in, const text_t& immuneChars, bool dmsafe) {
+  text_t out;
+  text_t::const_iterator here = in.begin();
+  text_t::const_iterator end = in.end();
+  while (here != end) {
+    out += encodeForJavascript(immuneChars, *here, dmsafe); // IMMUNE_JAVASCRIPT by default
+    ++here;
+  }
+  return out;
+}
+
 
 text_t encodeForMySQL(const text_t& in, const text_t& immuneChars, const SQLMode mode) {
@@ -259,5 +260,5 @@
 
 // http://code.google.com/p/owasp-esapi-java/source/browse/trunk/src/main/java/org/owasp/esapi/codecs/JavaScriptCodec.java
-text_t encodeForJavascript(const text_t& immuneChars, const unsigned short in) {
+text_t encodeForJavascript(const text_t& immuneChars, const unsigned short in, bool dmsafe) {
   
   text_t result = "";
@@ -294,5 +295,10 @@
       char hex_char[3];
       sprintf(hex_char,"%02X",in);
-      result = "\\x" + text_t(hex_char);
+
+      if(dmsafe) { // double escape backslashes for macro files
+	result = "\\\\x" + text_t(hex_char);
+      } else {
+	result = "\\x" + text_t(hex_char);
+      }
     }
     // otherwise encode with \\uHHHH
@@ -300,5 +306,9 @@
       char hex_char[5];
       sprintf(hex_char,"%04X",in);
-      result = "\\u" + text_t(hex_char);
+      if(dmsafe) { // double escape backslashes for macro files
+	result = "\\\\u" + text_t(hex_char);
+      } else {
+	result = "\\u" + text_t(hex_char);      
+      }
     }
     
Index: main/trunk/greenstone2/runtime-src/src/recpt/securitytools.h
===================================================================
--- main/trunk/greenstone2/runtime-src/src/recpt/securitytools.h	(revision 28888)
+++ main/trunk/greenstone2/runtime-src/src/recpt/securitytools.h	(revision 28898)
@@ -25,5 +25,5 @@
 text_t encodeForHTML(const text_t& input, const text_t& immuneChars=IMMUNE_HTML);
 text_t encodeForURL(const text_t& input, const text_t& immuneChars=IMMUNE_URL);
-text_t encodeForJavascript(const text_t& input, const text_t& immuneChars=IMMUNE_JAVASCRIPT);
+text_t encodeForJavascript(const text_t& input, const text_t& immuneChars=IMMUNE_JAVASCRIPT, bool dmsafe=true);
 text_t encodeForHTMLAttr(const text_t& input, const text_t& immuneChars=IMMUNE_HTMLATTR);
 text_t encodeForCSS(const text_t& input, const text_t& immuneChars=IMMUNE_CSS);
@@ -33,5 +33,5 @@
 text_t encodeForHTML(const text_t& immuneChars, const unsigned short input);
 text_t encodeForURL(const text_t& immuneChars, const unsigned short input);
-text_t encodeForJavascript(const text_t& immuneChars, const unsigned short input);
+text_t encodeForJavascript(const text_t& immuneChars, const unsigned short input, bool dmsafe);
 text_t encodeForCSS(const text_t& immuneChars, const unsigned short input);
 text_t encodeForMySQL(const text_t& immuneChars, const unsigned short input, const SQLMode mode);
