#29 ✓resolved
Deleted User

[PATCH] NULL pointer when label_elements loops up parent chain

Reported by Deleted User | November 11th, 2008 @ 09:56 AM

When using webrat to click the save button on the following form using click_button("Save"), I'm getting the following error:


NULL pointer given
/Users/rupert/Sites/home/merb/apsc_new/gems/gems/webrat-0.3.2/lib/webrat/core/field.rb:106:in `name'
/Users/rupert/Sites/home/merb/apsc_new/gems/gems/webrat-0.3.2/lib/webrat/core/field.rb:106:in `label_elements'
/Users/rupert/Sites/home/merb/apsc_new/gems/gems/webrat-0.3.2/lib/webrat/core/field.rb:97:in `labels'
/Users/rupert/Sites/home/merb/apsc_new/gems/gems/webrat-0.3.2/lib/webrat/core/field.rb:44:in `matches_label?'
/Users/rupert/Sites/home/merb/apsc_new/gems/gems/webrat-0.3.2/lib/webrat/core/form.rb:64:in `field_labeled'
/Users/rupert/Sites/home/merb/apsc_new/gems/gems/webrat-0.3.2/lib/webrat/core/form.rb:63:in `select'
/Users/rupert/Sites/home/merb/apsc_new/gems/gems/webrat-0.3.2/lib/webrat/core/form.rb:63:in `field_labeled'
/Users/rupert/Sites/home/merb/apsc_new/gems/gems/webrat-0.3.2/lib/webrat/core/form.rb:17:in `field'
/Users/rupert/Sites/home/merb/apsc_new/gems/gems/webrat-0.3.2/lib/webrat/core/field.rb:174:in `to_param'
/Users/rupert/Sites/home/merb/apsc_new/gems/gems/webrat-0.3.2/lib/webrat/core/form.rb:83:in `params'
/Users/rupert/Sites/home/merb/apsc_new/gems/gems/webrat-0.3.2/lib/webrat/core/form.rb:82:in `each'
/Users/rupert/Sites/home/merb/apsc_new/gems/gems/webrat-0.3.2/lib/webrat/core/form.rb:82:in `params'
/Users/rupert/Sites/home/merb/apsc_new/gems/gems/webrat-0.3.2/lib/webrat/core/form.rb:48:in `submit'
/Users/rupert/Sites/home/merb/apsc_new/gems/gems/webrat-0.3.2/lib/webrat/core/field.rb:163:in `click'
/Users/rupert/Sites/home/merb/apsc_new/gems/gems/webrat-0.3.2/lib/webrat/core/scope.rb:149:in `click_button'
(eval):3:in `click_button'

This is the page containing the offending form:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-us" lang="en-us">
  <head>
    <title>Fresh Merb App</title>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <link rel="stylesheet" href="/stylesheets/master.css" type="text/css" media="screen" charset="utf-8" />
  </head>
  <body>

    <h1>Manually Entered Forms controller, subscription information (new)</h1>

<form method="post" action="/manually_entered_subscriptions"><input type="hidden" value="put" name="_method"/>

  <h2>Subscription Details</h2>
<input type="hidden" value="0" class="hidden" name="manually_entered_subscription[life_member]"/><input type="checkbox" class="checkbox" value="1" name="manually_entered_subscription[life_member]" id="manually_entered_subscription_life_member"/>



<input type="submit" value="Save" name="submit"/>


</form>
  </body>
</html>

However when doing the same thing on this form, all is OK.


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-us" lang="en-us">
  <head>
    <title>Fresh Merb App</title>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <link rel="stylesheet" href="/stylesheets/master.css" type="text/css" media="screen" charset="utf-8" />
  </head>
  <body>

    <h1>Manually Entered Forms controller, subscription information (new)</h1>

<form method="post" action="/manually_entered_subscriptions">

  <h2>Subscription Details</h2>
<input type="hidden" value="0" class="hidden" name="manually_entered_subscription[life_member]"/><input type="checkbox" class="checkbox" value="1" name="manually_entered_subscription[life_member]" id="manually_entered_subscription_life_member"/>



<input type="submit" value="Save" name="submit"/>


</form>
  </body>
</html>

The only difference between the forms is that the problematic one has a rails/merb style hidden input for making the form act as a put form:


<input type="hidden" value="put" name="_method"/>

From running the debugger, things are going tits-up in the label_elements method of webrat/core/field.rb when it's looping up the parent chain. It throws a wobbly when accessing parent.name when the parent reaches the root:


<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-us" lang="en-us" xml:lang="en-us">
  <head>
    <title>Fresh Merb App</title>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <link rel="stylesheet" href="/stylesheets/master.css" type="text/css" media="screen" charset="utf-8" />
  </head>
  <body>

    <h1>Manually Entered Forms controller, subscription information (new)</h1>

<form method="post" action="/manually_entered_subscriptions"><input type="hidden" value="put" name="_method" /><h2>Subscription Details</h2>
<input type="hidden" value="0" class="hidden" name="manually_entered_subscription[life_member]" /><input type="checkbox" class="checkbox" value="1" name="manually_entered_subscription[life_member]" id="manually_entered_subscription_life_member" /><input type="submit" value="Save" name="submit" /></form>
  </body>
</html>

I've added a patch which fixes this, but there are no specs for it as I wasn't sure where to put them (the patch doesn't cause any other specs to fail though).

This may also fixe ticket #28 as it seems to be related to the same problem but I haven't checked.

Comments and changes to this ticket

  • Deleted User

    Deleted User November 11th, 2008 @ 10:39 AM

    • Title changed from “NULL pointer when label_elements loops up parent chain” to “[PATCH] NULL pointer when label_elements loops up parent chain”
  • rssaddict

    rssaddict November 11th, 2008 @ 12:13 PM

    I can confirm that this patch also fixes the problem I had (ticket #28)

  • Bryan Helmkamp

    Bryan Helmkamp November 13th, 2008 @ 11:23 PM

    Hey Rupert,

    Thanks for the patch. I'm having trouble replicating the problem though as you described though. Does this still happen to you on the latest code?

    If so, can you add a failing test case to your patch please? I tried to create one but couldn't.

    Cheers,

    -Bryan

  • Deleted User

    Deleted User November 14th, 2008 @ 05:20 AM

    Hi Bryan

    I've just had a dig around and the problem was with nokogiri and not webrat phew.

    Upgrading nokogiri from v1.0.4 to 1.0.5 fixed it. The relevant commit is http://github.com/tenderlove/nok... (checking for nil pointer before returning name). With v1.0.4 nokogiri was throwing a wobbly when label_elements was looping up the parents and calling parent.name when it got to the top of the tree - now all's OK as it's got a check in place.

    So all it needed was a bit of tenderlove to fix the problem - how sweet :) Ticket closed I guess and probably #28 too if it fixes rssadict's issue too (which I think it probably will)

    Cheers

    Rupert

  • rssaddict

    rssaddict November 14th, 2008 @ 09:36 AM

    Yep, all clear for my issue too. Thanks guys.

  • Bryan Helmkamp

    Bryan Helmkamp November 14th, 2008 @ 10:35 AM

    • State changed from “new” to “resolved”

    Great. Thanks for tracking this down and confirming it's all set. I'm going to close this out.

  • Deleted User

    Deleted User November 14th, 2008 @ 10:38 AM

    My pleasure - specially as webrat is just so totally awesome :)

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

Ruby Acceptance Testing for Web applications.

Shared Ticket Bins

People watching this ticket

Attachments

Referenced by

Pages