Bug 32342

Summary: Javascript string comparison
Product: WebKit Reporter: Matt O <matt>
Component: JavaScriptCoreAssignee: Nobody <webkit-unassigned>
Status: RESOLVED DUPLICATE    
Severity: Normal CC: mjs
Priority: P2 Keywords: HasReduction, InRadar
Version: 528+ (Nightly build)   
Hardware: Mac (Intel)   
OS: OS X 10.6   

Description Matt O 2009-12-09 12:49:06 PST
This broken with the nightly build from Monday, Dec 7.  Javascript appears to be evaluating the following code properly in console until you get to the last line.  The expression is always being evaluated as "true".

mystring = "02122010";
digits = mystring.substr(2,2);

console.log("Digits value:");
console.log(digits);

console.log("Digits type:");
console.log(typeof digits);

console.log("This expression evaluates correctly as false: (digits > 12)");
console.log(digits < 1);

console.log("This expression evaluates correctly as false: (digits > 12)");
console.log(digits > 12);

console.log("This expression evaluates correctly as false: (digits < 1) || (digits > 12)");
console.log((digits < 1) || (digits > 12));

console.log("But it fails in real use:  if ((digits < 1) || (digits > 12)) { console.log(\"Sorry, I don't like strings - even though I should.\"); }")
if ((digits < 1) || (digits > 12)) { console.log("Sorry, I don't like strings - even though I should."); }
Comment 1 Mark Rowe (bdash) 2009-12-09 13:41:25 PST
<rdar://problem/7457885>
Comment 2 Maciej Stachowiak 2009-12-09 23:01:07 PST
This is caused by the same underlying bug as bug 32256. Marking duplicate of the higher-numbered bug because the other bug better reflects the impact.

*** This bug has been marked as a duplicate of bug 32256 ***