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 24description( 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 31var 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 34var Ci=/\s+/g; 35var BC=/^ /; 36var BG=/ $/; 37 38// Strips leading Re or similar (from Gmail source) 39function 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) 52function Gn(a) { 53 return a.replace(Ci, " ").replace(BC, "").replace(BG, ""); 54} 55 56shouldBe("cy('Re: Moose')", "'Moose'") 57shouldBe("cy('\\u8f6c\\u53d1: Moose')", "'Moose'") 58 59// Test handling of \u2820 (skull and crossbones) 60var sample="sample bm\u2820p cm\\u2820p"; 61 62var inlineRe=/.m\u2820p/ 63var evalInlineRe=eval("/.m\\u2820p/") 64var explicitRe=new RegExp(".m\\u2820p") 65var newFromInlineRe=new RegExp(inlineRe.source) 66var evalFromInlineRe=eval(inlineRe.toString()) 67var newFromEvalInlineRe=new RegExp(evalInlineRe.source) 68var evalFromEvalInlineRe=eval(evalInlineRe.toString()) 69var newFromExplicitRe=new RegExp(explicitRe.source) 70var evalFromExplicitRe=eval(explicitRe.toString()) 71 72shouldBe("inlineRe.source", "newFromInlineRe.source") 73shouldBe("inlineRe.source", "evalFromInlineRe.source") 74shouldBe("inlineRe.source", "evalInlineRe.source") 75shouldBe("inlineRe.source", "newFromEvalInlineRe.source") 76shouldBe("inlineRe.source", "evalFromEvalInlineRe.source") 77shouldBe("inlineRe.source", "explicitRe.source") 78shouldBe("inlineRe.source", "newFromExplicitRe.source") 79shouldBe("inlineRe.source", "evalFromExplicitRe.source") 80 81shouldBe("inlineRe.toString()", "newFromInlineRe.toString()") 82shouldBe("inlineRe.toString()", "evalFromInlineRe.toString()") 83shouldBe("inlineRe.toString()", "evalInlineRe.toString()") 84shouldBe("inlineRe.toString()", "newFromEvalInlineRe.toString()") 85shouldBe("inlineRe.toString()", "evalFromEvalInlineRe.toString()") 86shouldBe("inlineRe.toString()", "explicitRe.toString()") 87shouldBe("inlineRe.toString()", "newFromExplicitRe.toString()") 88shouldBe("inlineRe.toString()", "evalFromExplicitRe.toString()") 89 90shouldBe("inlineRe.exec(sample)[0]", "'bm\u2820p'") 91shouldBe("evalInlineRe.exec(sample)[0]", "'bm\u2820p'") 92shouldBe("explicitRe.exec(sample)[0]", "'bm\u2820p'") 93 94 95// Test handling of \u007c "|" 96var bsample="sample bm\u007cp cm\\u007cp"; 97 98var binlineRe=/.m\u007cp/ 99var bevalInlineRe=eval("/.m\\u007cp/") 100var bexplicitRe=new RegExp(".m\\u007cp") 101var bnewFromInlineRe=new RegExp(binlineRe.source) 102var bevalFromInlineRe=eval(binlineRe.toString()) 103var bnewFromEvalInlineRe=new RegExp(bevalInlineRe.source) 104var bevalFromEvalInlineRe=eval(bevalInlineRe.toString()) 105var bnewFromExplicitRe=new RegExp(bexplicitRe.source) 106var bevalFromExplicitRe=eval(bexplicitRe.toString()) 107 108shouldBe("binlineRe.source", "bnewFromInlineRe.source") 109shouldBe("binlineRe.source", "bevalFromInlineRe.source") 110shouldBe("binlineRe.source", "bevalInlineRe.source") 111shouldBe("binlineRe.source", "bnewFromEvalInlineRe.source") 112shouldBe("binlineRe.source", "bevalFromEvalInlineRe.source") 113shouldBe("binlineRe.source", "bexplicitRe.source") 114shouldBe("binlineRe.source", "bnewFromExplicitRe.source") 115shouldBe("binlineRe.source", "bevalFromExplicitRe.source") 116 117shouldBe("binlineRe.toString()", "bnewFromInlineRe.toString()") 118shouldBe("binlineRe.toString()", "bevalFromInlineRe.toString()") 119shouldBe("binlineRe.toString()", "bevalInlineRe.toString()") 120shouldBe("binlineRe.toString()", "bnewFromEvalInlineRe.toString()") 121shouldBe("binlineRe.toString()", "bevalFromEvalInlineRe.toString()") 122shouldBe("binlineRe.toString()", "bexplicitRe.toString()") 123shouldBe("binlineRe.toString()", "bnewFromExplicitRe.toString()") 124shouldBe("binlineRe.toString()", "bevalFromExplicitRe.toString()") 125 126shouldBe("binlineRe.exec(bsample)[0]", "'bm|p'") 127shouldBe("bevalInlineRe.exec(bsample)[0]", "'bm|p'") 128shouldBe("bexplicitRe.exec(bsample)[0]", "'bm|p'") 129