<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>41913</bug_id>
          
          <creation_ts>2010-07-08 15:36:20 -0700</creation_ts>
          <short_desc>XPath substring function does not correctly handle non-positive values for the position argument</short_desc>
          <delta_ts>2010-07-12 03:44:13 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>XML</component>
          <version>528+ (Nightly build)</version>
          <rep_platform>All</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Steve Block">steveblock</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>ap</cc>
    
    <cc>benm</cc>
    
    <cc>steveblock</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>248593</commentid>
    <comment_count>0</comment_count>
    <who name="Steve Block">steveblock</who>
    <bug_when>2010-07-08 15:36:20 -0700</bug_when>
    <thetext>In the XPath substring function, if a negative value is supplied for the position argument and a length argument is present, we reset the position argument to the first character of the string and adjust the length argument such that the final character in the substring is the same as it would have been if the length were counted from the original negative position value. We then return the substring using the new position and length.

However, in the case where no length argument is present, we call String::substring() with the negative position value. Since String::substring() takes two unsigned int arguments, the position value gets wrapped to a large integer and we likely return the empty string because the wrapped position value exceeds the string length. This seems incorrect and is inconsistent with the above case.

See Bug 41862 for some background.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>249066</commentid>
    <comment_count>1</comment_count>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2010-07-09 10:02:35 -0700</bug_when>
    <thetext>Yes, substring(&quot;12345&quot;, -1) should return &quot;12345&quot;. This is not only about negative numbers -substring(&quot;12345&quot;, 0) is also wrong for the same reason.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>249070</commentid>
    <comment_count>2</comment_count>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2010-07-09 10:06:16 -0700</bug_when>
    <thetext>See &lt;http://www.w3.org/TR/xpath/#function-substring&gt;.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>249071</commentid>
    <comment_count>3</comment_count>
    <who name="Steve Block">steveblock</who>
    <bug_when>2010-07-09 10:07:02 -0700</bug_when>
    <thetext>&gt; Yes, substring(&quot;12345&quot;, -1) should return &quot;12345&quot;. This is not only about
&gt; negative numbers -substring(&quot;12345&quot;, 0) is also wrong for the same reason.
Yes, I meant non-positive numbers. Patch coming soon.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>249085</commentid>
    <comment_count>4</comment_count>
      <attachid>61054</attachid>
    <who name="Steve Block">steveblock</who>
    <bug_when>2010-07-09 10:17:33 -0700</bug_when>
    <thetext>Created attachment 61054
Patch</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>249110</commentid>
    <comment_count>5</comment_count>
      <attachid>61054</attachid>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2010-07-09 10:55:51 -0700</bug_when>
    <thetext>Comment on attachment 61054
Patch

&gt; +        we reset the position to 1. This matches the current behaviour when a length
&gt; +        argument is supplied.

This fix is not really about consistency - there is a rigorous spec, and we now match it. Does the new test pass in Firefox?

r=me</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>249732</commentid>
    <comment_count>6</comment_count>
    <who name="Steve Block">steveblock</who>
    <bug_when>2010-07-12 02:51:20 -0700</bug_when>
    <thetext>&gt; This fix is not really about consistency - there is a rigorous spec, and we 
&gt; now match it.
OK, have updated the bug title and will land with an updated description

&gt; Does the new test pass in Firefox?
Yes</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>249745</commentid>
    <comment_count>7</comment_count>
    <who name="Steve Block">steveblock</who>
    <bug_when>2010-07-12 03:44:13 -0700</bug_when>
    <thetext>Committed r63066: &lt;http://trac.webkit.org/changeset/63066&gt;</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>61054</attachid>
            <date>2010-07-09 10:17:33 -0700</date>
            <delta_ts>2010-07-09 10:55:51 -0700</delta_ts>
            <desc>Patch</desc>
            <filename>bug-41913-20100709181731.patch</filename>
            <type>text/plain</type>
            <size>4669</size>
            <attacher name="Steve Block">steveblock</attacher>
            
              <data encoding="base64">SW5kZXg6IFdlYkNvcmUvQ2hhbmdlTG9nCj09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT0KLS0tIFdlYkNvcmUvQ2hhbmdlTG9n
CShyZXZpc2lvbiA2Mjk2MSkKKysrIFdlYkNvcmUvQ2hhbmdlTG9nCSh3b3JraW5nIGNvcHkpCkBA
IC0xLDMgKzEsMjAgQEAKKzIwMTAtMDctMDkgIFN0ZXZlIEJsb2NrICA8c3RldmVibG9ja0Bnb29n
bGUuY29tPgorCisgICAgICAgIFJldmlld2VkIGJ5IE5PQk9EWSAoT09QUyEpLgorCisgICAgICAg
IFhQYXRoIHN1YnN0cmluZyBmdW5jdGlvbiBoYXMgaW5jb25zaXN0ZW50IGhhbmRsaW5nIG9mIG5v
bi1wb3NpdGl2ZSB2YWx1ZXMgZm9yIHRoZSBwb3NpdGlvbiBhcmd1bWVudAorICAgICAgICBodHRw
czovL2J1Z3Mud2Via2l0Lm9yZy9zaG93X2J1Zy5jZ2k/aWQ9NDE5MTMKKworICAgICAgICBUaGlz
IHBhdGNoIGNoYW5nZXMgdGhlIG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U
UklOR19UWVBFLCBudWxsKS5zdHJpbmdWYWx1ZSIsICInYWInIik7CisKKyAgICB2YXIgc3VjY2Vz
c2Z1bGx5UGFyc2VkID0gdHJ1ZTsKKworPC9zY3JpcHQ+Cis8c2NyaXB0IHNyYz0iLi4vanMvcmVz
b3VyY2VzL2pzLXRlc3QtcG9zdC5qcyI+PC9zY3JpcHQ+Cis8L2JvZHk+Cis8L2h0bWw+Cg==
</data>
<flag name="review"
          id="49010"
          type_id="1"
          status="+"
          setter="ap"
    />
          </attachment>
      

    </bug>

</bugzilla>