1 // Copyright 2013 the V8 project authors. All rights reserved. 2 // Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. 3 // 4 // Redistribution and use in source and binary forms, with or without 5 // modification, are permitted provided that the following conditions 6 // are met: 7 // 1. Redistributions of source code must retain the above copyright 8 // notice, this list of conditions and the following disclaimer. 9 // 2. Redistributions in binary form must reproduce the above copyright 10 // notice, this list of conditions and the following disclaimer in the 11 // documentation and/or other materials provided with the distribution. 12 // 13 // THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY 14 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 15 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 16 // DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY 17 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 18 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 19 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 22 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 24 description( 25 26 'Test for proper handling of Unicode RegExps and <a href="http://bugzilla.webkit.org/show_bug.cgi?id=7445">bug 7445</a>: Gmail puts wrong subject in replies.' 27 28 ); 29 30 // Regex to match Re in various languanges straight from Gmail source 31 var I3=/^\s*(fwd|re|aw|antw|antwort|wg|sv|ang|odp|betreff|betr|transf|reenv\.|reenv|in|res|resp|resp\.|enc|\u8f6c\u53d1|\u56DE\u590D|\u041F\u0435\u0440\u0435\u0441\u043B|\u041E\u0442\u0432\u0435\u0442):\s*(.*)$/i; 32 33 // Other RegExs from Gmail source 34 var Ci=/\s+/g; 35 var BC=/^ /; 36 var BG=/ $/; 37 38 // Strips leading Re or similar (from Gmail source) 39 function cy(a) { 40 //var b = I3.exec(a); 41 var b = I3.exec(a); 42 43 if (b) { 44 a = b[2]; 45 } 46 47 return Gn(a); 48 } 49 50 // This function replaces consecutive whitespace with a single space 51 // then removes a leading and trailing space if they exist. (From Gmail) 52 function Gn(a) { 53 return a.replace(Ci, " ").replace(BC, "").replace(BG, ""); 54 } 55 56 shouldBe("cy('Re: Moose')", "'Moose'") 57 shouldBe("cy('\\u8f6c\\u53d1: Moose')", "'Moose'") 58 59 // Test handling of \u2820 (skull and crossbones) 60 var sample="sample bm\u2820p cm\\u2820p"; 61 62 var inlineRe=/.m\u2820p/ 63 var evalInlineRe=eval("/.m\\u2820p/") 64 var explicitRe=new RegExp(".m\\u2820p") 65 var newFromInlineRe=new RegExp(inlineRe.source) 66 var evalFromInlineRe=eval(inlineRe.toString()) 67 var newFromEvalInlineRe=new RegExp(evalInlineRe.source) 68 var evalFromEvalInlineRe=eval(evalInlineRe.toString()) 69 var newFromExplicitRe=new RegExp(explicitRe.source) 70 var evalFromExplicitRe=eval(explicitRe.toString()) 71 72 shouldBe("inlineRe.source", "newFromInlineRe.source") 73 shouldBe("inlineRe.source", "evalFromInlineRe.source") 74 shouldBe("inlineRe.source", "evalInlineRe.source") 75 shouldBe("inlineRe.source", "newFromEvalInlineRe.source") 76 shouldBe("inlineRe.source", "evalFromEvalInlineRe.source") 77 shouldBe("inlineRe.source", "explicitRe.source") 78 shouldBe("inlineRe.source", "newFromExplicitRe.source") 79 shouldBe("inlineRe.source", "evalFromExplicitRe.source") 80 81 shouldBe("inlineRe.toString()", "newFromInlineRe.toString()") 82 shouldBe("inlineRe.toString()", "evalFromInlineRe.toString()") 83 shouldBe("inlineRe.toString()", "evalInlineRe.toString()") 84 shouldBe("inlineRe.toString()", "newFromEvalInlineRe.toString()") 85 shouldBe("inlineRe.toString()", "evalFromEvalInlineRe.toString()") 86 shouldBe("inlineRe.toString()", "explicitRe.toString()") 87 shouldBe("inlineRe.toString()", "newFromExplicitRe.toString()") 88 shouldBe("inlineRe.toString()", "evalFromExplicitRe.toString()") 89 90 shouldBe("inlineRe.exec(sample)[0]", "'bm\u2820p'") 91 shouldBe("evalInlineRe.exec(sample)[0]", "'bm\u2820p'") 92 shouldBe("explicitRe.exec(sample)[0]", "'bm\u2820p'") 93 94 95 // Test handling of \u007c "|" 96 var bsample="sample bm\u007cp cm\\u007cp"; 97 98 var binlineRe=/.m\u007cp/ 99 var bevalInlineRe=eval("/.m\\u007cp/") 100 var bexplicitRe=new RegExp(".m\\u007cp") 101 var bnewFromInlineRe=new RegExp(binlineRe.source) 102 var bevalFromInlineRe=eval(binlineRe.toString()) 103 var bnewFromEvalInlineRe=new RegExp(bevalInlineRe.source) 104 var bevalFromEvalInlineRe=eval(bevalInlineRe.toString()) 105 var bnewFromExplicitRe=new RegExp(bexplicitRe.source) 106 var bevalFromExplicitRe=eval(bexplicitRe.toString()) 107 108 shouldBe("binlineRe.source", "bnewFromInlineRe.source") 109 shouldBe("binlineRe.source", "bevalFromInlineRe.source") 110 shouldBe("binlineRe.source", "bevalInlineRe.source") 111 shouldBe("binlineRe.source", "bnewFromEvalInlineRe.source") 112 shouldBe("binlineRe.source", "bevalFromEvalInlineRe.source") 113 shouldBe("binlineRe.source", "bexplicitRe.source") 114 shouldBe("binlineRe.source", "bnewFromExplicitRe.source") 115 shouldBe("binlineRe.source", "bevalFromExplicitRe.source") 116 117 shouldBe("binlineRe.toString()", "bnewFromInlineRe.toString()") 118 shouldBe("binlineRe.toString()", "bevalFromInlineRe.toString()") 119 shouldBe("binlineRe.toString()", "bevalInlineRe.toString()") 120 shouldBe("binlineRe.toString()", "bnewFromEvalInlineRe.toString()") 121 shouldBe("binlineRe.toString()", "bevalFromEvalInlineRe.toString()") 122 shouldBe("binlineRe.toString()", "bexplicitRe.toString()") 123 shouldBe("binlineRe.toString()", "bnewFromExplicitRe.toString()") 124 shouldBe("binlineRe.toString()", "bevalFromExplicitRe.toString()") 125 126 shouldBe("binlineRe.exec(bsample)[0]", "'bm|p'") 127 shouldBe("bevalInlineRe.exec(bsample)[0]", "'bm|p'") 128 shouldBe("bexplicitRe.exec(bsample)[0]", "'bm|p'") 129