DEFPRINT(AST_RegExp, function(self, output) {
var regexp = self.value;
var str = regexp.toString();
+ var end = str.lastIndexOf("/");
if (regexp.raw_source) {
- str = "/" + regexp.raw_source + str.slice(str.lastIndexOf("/"));
+ str = "/" + regexp.raw_source + str.slice(end);
+ } else if (end == 1) {
+ str = "/(?:)" + str.slice(end);
+ } else if (str.indexOf("/", 1) < end) {
+ str = "/" + str.slice(1, end).replace(/\\\\|[^/]?\//g, function(match) {
+ return match[0] == "\\" ? match : match.slice(0, -1) + "\\/";
+ }) + str.slice(end);
}
- output.print(output.to_utf8(str).replace(/\\(?:\0(?![0-9])|[^\0])/g, function(seq) {
- switch (seq[1]) {
+ output.print(output.to_utf8(str).replace(/\\(?:\0(?![0-9])|[^\0])/g, function(match) {
+ switch (match[1]) {
case "\n": return "\\n";
case "\r": return "\\r";
case "\t": return "\t";
case "\x0B": return "\v";
case "\u2028": return "\\u2028";
case "\u2029": return "\\u2029";
- default: return seq;
+ default: return match;
}
}).replace(/[\n\r\u2028\u2029]/g, function(c) {
switch (c) {
/\nfo\n[\n]o\bbb/;
}
}
+
+issue_3434_4: {
+ options = {
+ evaluate: true,
+ unsafe: true,
+ }
+ input: {
+ [
+ [ "", RegExp("") ],
+ [ "/", RegExp("/") ],
+ [ "//", RegExp("//") ],
+ [ "\/", RegExp("\\/") ],
+ [ "///", RegExp("///") ],
+ [ "/\/", RegExp("/\\/") ],
+ [ "\//", RegExp("\\//") ],
+ [ "\\/", RegExp("\\\\/") ],
+ [ "////", RegExp("////") ],
+ [ "//\/", RegExp("//\\/") ],
+ [ "/\//", RegExp("/\\//") ],
+ [ "/\\/", RegExp("/\\\\/") ],
+ [ "\///", RegExp("\\///") ],
+ [ "\/\/", RegExp("\\/\\/") ],
+ [ "\\//", RegExp("\\\\//") ],
+ [ "\\\/", RegExp("\\\\\\/") ],
+ ].forEach(function(test) {
+ console.log(test[1].test("\\"), test[1].test(test[0]));
+ });
+ }
+ expect: {
+ [
+ [ "", /(?:)/ ],
+ [ "/", /\// ],
+ [ "//", /\/\// ],
+ [ "/", /\// ],
+ [ "///", /\/\/\// ],
+ [ "//", /\/\// ],
+ [ "//", /\/\// ],
+ [ "\\/", /\\\// ],
+ [ "////", /\/\/\/\// ],
+ [ "///", /\/\/\// ],
+ [ "///", /\/\/\// ],
+ [ "/\\/", /\/\\\// ],
+ [ "///", /\/\/\// ],
+ [ "//", /\/\// ],
+ [ "\\//", /\\\/\// ],
+ [ "\\/", /\\\// ],
+ ].forEach(function(test) {
+ console.log(test[1].test("\\"), test[1].test(test[0]));
+ });
+ }
+ expect_stdout: [
+ "true true",
+ "false true",
+ "false true",
+ "false true",
+ "false true",
+ "false true",
+ "false true",
+ "false true",
+ "false true",
+ "false true",
+ "false true",
+ "false true",
+ "false true",
+ "false true",
+ "false true",
+ "false true",
+ ]
+}