<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; }
#msg ul, pre { overflow: auto; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<title>[19957] trunk/WebCore</title>
</head>
<body>
<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/19957">19957</a></dd>
<dt>Author</dt> <dd>ap</dd>
<dt>Date</dt> <dd>2007-03-04 21:34:10 -0800 (Sun, 04 Mar 2007)</dd>
</dl>
<h3>Log Message</h3>
<pre> Reviewed by Nikolas Zimmermann (yay!).
http://bugs.webkit.org/show_bug.cgi?id=12962
4XPath tests crash on lang() function
Covered by 4XPath tests, to be landed later.
* platform/StringImpl.cpp:
(WebCore::StringImpl::reverseFind): Do not crash with empty strings.
* xml/XPathFunctions.cpp:
(WebCore::XPath::FunLang::doEvaluate): Do not crash when an element has no
attributes. Use a proper namespace for xml:lang (not sure where "xms" came from).
Rewrote the algorithm for suffix removing to match the spec.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkWebCoreChangeLog">trunk/WebCore/ChangeLog</a></li>
<li><a href="#trunkWebCoreplatformStringImplcpp">trunk/WebCore/platform/StringImpl.cpp</a></li>
<li><a href="#trunkWebCorexmlXPathFunctionscpp">trunk/WebCore/xml/XPathFunctions.cpp</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/WebCore/ChangeLog (19956 => 19957)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/WebCore/ChangeLog        2007-03-05 01:33:33 UTC (rev 19956)
+++ trunk/WebCore/ChangeLog        2007-03-05 05:34:10 UTC (rev 19957)
</span><span class="lines">@@ -1,3 +1,19 @@
</span><ins>+2007-03-04 Alexey Proskuryakov <ap@webkit.org>
+
+ Reviewed by Nikolas Zimmermann (yay!).
+
+ http://bugs.webkit.org/show_bug.cgi?id=12962
+ 4XPath tests crash on lang() function
+
+ Covered by 4XPath tests, to be landed later.
+
+ * platform/StringImpl.cpp:
+ (WebCore::StringImpl::reverseFind): Do not crash with empty strings.
+ * xml/XPathFunctions.cpp:
+ (WebCore::XPath::FunLang::doEvaluate): Do not crash when an element has no
+ attributes. Use a proper namespace for xml:lang (not sure where "xms" came from).
+ Rewrote the algorithm for suffix removing to match the spec.
+
</ins><span class="cx"> 2007-03-02 Anders Carlsson <acarlsson@apple.com>
</span><span class="cx">
</span><span class="cx"> Reviewed by Darin.
</span></span></pre></div>
<a id="trunkWebCoreplatformStringImplcpp"></a>
<div class="modfile"><h4>Modified: trunk/WebCore/platform/StringImpl.cpp (19956 => 19957)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/WebCore/platform/StringImpl.cpp        2007-03-05 01:33:33 UTC (rev 19956)
+++ trunk/WebCore/platform/StringImpl.cpp        2007-03-05 05:34:10 UTC (rev 19957)
</span><span class="lines">@@ -777,7 +777,7 @@
</span><span class="cx">
</span><span class="cx"> int StringImpl::reverseFind(const UChar c, int index) const
</span><span class="cx"> {
</span><del>- if (index >= (int)m_length)
</del><ins>+ if (index >= (int)m_length || m_length == 0)
</ins><span class="cx"> return -1;
</span><span class="cx">
</span><span class="cx"> if (index < 0)
</span></span></pre></div>
<a id="trunkWebCorexmlXPathFunctionscpp"></a>
<div class="modfile"><h4>Modified: trunk/WebCore/xml/XPathFunctions.cpp (19956 => 19957)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/WebCore/xml/XPathFunctions.cpp        2007-03-05 01:33:33 UTC (rev 19956)
+++ trunk/WebCore/xml/XPathFunctions.cpp        2007-03-05 05:34:10 UTC (rev 19957)
</span><span class="lines">@@ -32,6 +32,7 @@
</span><span class="cx">
</span><span class="cx"> #include "Document.h"
</span><span class="cx"> #include "NamedAttrMap.h"
</span><ins>+#include "XMLNames.h"
</ins><span class="cx"> #include "XPathValue.h"
</span><span class="cx"> #include <wtf/MathExtras.h>
</span><span class="cx">
</span><span class="lines">@@ -596,10 +597,10 @@
</span><span class="cx">
</span><span class="cx"> RefPtr<Node> langNode = 0;
</span><span class="cx"> Node* node = evaluationContext().node.get();
</span><del>- String xmsnsURI = node->lookupNamespaceURI("xms");
</del><span class="cx"> while (node) {
</span><span class="cx"> NamedAttrMap* attrs = node->attributes();
</span><del>- langNode = attrs->getNamedItemNS(xmsnsURI, "lang");
</del><ins>+ if (attrs)
+ langNode = attrs->getNamedItemNS(XMLNames::xmlNamespaceURI, "lang");
</ins><span class="cx"> if (langNode)
</span><span class="cx"> break;
</span><span class="cx"> node = node->parentNode();
</span><span class="lines">@@ -609,13 +610,18 @@
</span><span class="cx"> return false;
</span><span class="cx">
</span><span class="cx"> String langNodeValue = langNode->nodeValue();
</span><ins>+ while (true) {
+ if (equalIgnoringCase(langNodeValue, lang))
+ return true;
</ins><span class="cx">
</span><del>- // extract 'en' out of 'en-us'
- int index = langNodeValue.find('-');
- if (index != -1)
</del><ins>+ // Remove suffixes one by one.
+ int index = langNodeValue.reverseFind('-');
+ if (index == -1)
+ break;
</ins><span class="cx"> langNodeValue = langNodeValue.left(index);
</span><ins>+ }
</ins><span class="cx">
</span><del>- return equalIgnoringCase(langNodeValue, lang);
</del><ins>+ return false;
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> bool FunLang::isConstant() const
</span></span></pre>
</div>
</div>
</body>
</html>