#501 ✓duplicate

$$ to allow for unconventional characters in id

Reported by Baselios | December 22nd, 2008 @ 03:41 PM

Safari 2 - Issues with findElements in Prototype

Actually Tobie L. is not responsible, but he's one of the best developers for Prototype, so I will assign the issue to him.

The problem only accurs in Prototype and not in Browser Safari 2.

This is the patch Landseer did and what I see as the reason for this to break. http://code.zikula.org/core/chan...

There's more on this issue here: http://groups.google.com/group/p...

The problem is the call to findElements() (prototype.js line 2831)

In this function simply uses xpath and: return document._getElementsByXPath(this.xpath, root);

in however, a switch statement is used because of the new selectorAPI, which if selectorsAPI == true, attempts:

Line 2845: results = $A(root.querySelectorAll(e)).map(Element.extend);

The trouble is in Chrome and Safari this happens:

Uncaught Error: SYNTAX_ERR: DOM Exception 12 http://localhost/myapp/app/js/pr... (line 2845)

I did some digging and found this: http://lists.macosforge.org/pipe...>

Which only relates to the DOM Exception, not to my app. However, I cannot find anything else on this.

Any ideas?

Comments and changes to this ticket

  • Juriy Zaytsev

    Juriy Zaytsev December 22nd, 2008 @ 08:08 PM

    • Tag set to needs_failing_test_case

    Please, attach a test case.

  • Baselios

    Baselios December 23rd, 2008 @ 11:39 PM

    • Tag cleared.

    Please take a look here, because this seems to have been an issue before.


    Another issue which might be related is:


    Therefor this seems to be a bug in WebKit therefor affecting both Chrome and Sarafi.

  • Juriy Zaytsev

    Juriy Zaytsev December 24th, 2008 @ 01:17 AM


    the ticket you linked to is about an HTMLOptionElement webkit bug. Is it somehow relevant to your issue?

    Once again, it would be much easier for us to figure out what goes wrong if you could attach a minimal testcase.

  • Baselios

    Baselios December 24th, 2008 @ 01:37 AM

    All I know is that it seems to be very much related to this issue: http://dev.rubyonrails.org/ticke...

    My simple row of code: (obj is a HTML LI ELEMENT) obj.select('a').first().addClassName('active');

    It returns undefined when calling to "obj.select('a')". Observe the HTML code is present when this code line runs.

    HTML code looks like this:

    <li><a href="">LINK 1</a></li>
    <li><a href="">LINK 2</a></li>
    <li><a href="">LINK 3</a></li>
    <li><a href="">LINK 4</a></li>

    I'm only getting this problem when I have Prototype.Browser.WebKit equal TRUE. This breaks in Safari and I have been testing this in IE6, IE7, FF2, FF3, Opera9.25.

    This code WORKS in Prototype but breaks when I updated to

    Safari developer tool complains about: Line 2845: results = $A(root.querySelectorAll(e)).map(Element.extend);

    Is this good enough information to give you an idea about the issue I'm facing ?

  • Juriy Zaytsev

    Juriy Zaytsev December 24th, 2008 @ 04:56 AM

    I made a testcase, but can't reproduce an error. Both Safari 3.1 and nightly WebKit builds work as expected (in both - quirks and standard modes).

    What's missing?

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
    <html lang="en">
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <script src="http://ajax.googleapis.com/ajax/libs/prototype/" type="text/javascript"></script>
        <ul style="display:none">
          <li><a href="#">link 1</a></li>
          <li><a href="#">link 2</a></li>
        <script type="text/javascript">
            var li = $$('li')[0];
  • Tobie Langel

    Tobie Langel December 30th, 2008 @ 02:52 PM

    • State changed from “new” to “bug”
  • Tobie Langel

    Tobie Langel December 30th, 2008 @ 02:59 PM

    • State changed from “bug” to “incomplete”
  • tc

    tc January 19th, 2009 @ 07:57 AM

    I've been suffering the same problem in a project for a client but have struggled to isolate a test case, but I think I've got it!

    @@@ HTML <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <script src="http://ajax.googleapis.com/ajax/libs/prototype/" type="text/javascript"></script>
    <ul id="listy::list">
      <li><a href="#">link 1</a></li>
      <li><a href="#">link 2</a></li>
    <script type="text/javascript">
    I noticed in the client's project they were using illegal characters in the id field. Note the **id="listy::list"**.
    The interesting thing is that **console.log($('listy::list'))** seems to return the correct Object (HTMLUListElement). However, the select is obviously failing.
    **console.log($('listy::list').select('a'))** returns null
    **console.log($('listy::list').select)** returns 
    function () {
          return __method.apply(null, [this].concat($A(arguments)));
    I'm unsure as to whether this makes it something that Prototype can make an allowance for or if it's a WebKit bug?
    btw, I'm using the latest WebKit nightly build r40023 built on 19 January 2009.
  • tc

    tc January 19th, 2009 @ 08:01 AM

    Eep, sorry for mucking up the MarkDown syntax. There doesn't appear to be a away to edit my previous post??

    Attached is the test case I found to break it.

    note: if it's unclear from the post above. To get it to break I added an illegal id value of Listy::List.

  • tc

    tc January 19th, 2009 @ 08:09 AM

    Sorry for the stream of messages. I don't know if this ticket is related or the same issue? #413

    I also noticed that $("Listy::List") will return the connect node however $$("#Listy::List") will not. (if there happened to be another element within the document with id="Listy" the $$ expression would return that instead.

  • tc

    tc January 19th, 2009 @ 08:22 AM

    Looking a little further it appears "::" should be a acceptable character in a name or id field.

    ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_), colons (), and periods (".").

    From http://www.w3.org/TR/html4/types...

    I do know when attempting a css selector on an id with a colon it needs escaping. Eg.

    #Listy\:\:List {
    font-size: 1.2em;

    I don't know if that relates in any way to the actual problem that's occurring?

  • Tobie Langel

    Tobie Langel January 19th, 2009 @ 08:22 AM

    • State changed from “incomplete” to “enhancement”
    • Title changed from “Safari 2 - Issues with findElements in Prototype” to “$$ to allow for unconventional characters in id”

    Currently this isn't supported. Supporting this would imply allowing syntax for escaping such as the following:

  • tc

    tc January 19th, 2009 @ 08:33 AM

    Sorry Tobie I think I might have misdirected there. My last comment was not to request "::" be supported. It was more just part of my own investigation. I think there is still a more sinister bug.

    Maybe this ticket needs splitting to 2. One based on the original request and the other with the title you've just changed it to?

    I wish I could edit my comments from above as I think this one highlights more of what is actually happening?


    *see the bottom section with my example console output*

  • Tobie Langel

    Tobie Langel January 19th, 2009 @ 02:07 PM

    That's related actually.

    In Webkit, support for Element#select uses the following trick:


    Using the ID of @element@ to contextualize document.querySelectorAll.

  • Geoffrey Pursell

    Geoffrey Pursell February 2nd, 2009 @ 05:51 PM

    Tobie, I'm seeing this issue in a case in which there are no unusual characters in the ID or class of the elements I'm trying to query.

    I've tried to produce a test case, but after a couple hours of effort, I can't make Safari reproduce the error. My money is on this being a deep, weird WebKit bug.

    I wonder if there's a strange unicode character that's snuck into my query somehow.

    Short-circuiting shouldUseSelectorsAPI() to always return false works fine as a workaround for now.

  • Tobie Langel

    Tobie Langel February 3rd, 2009 @ 12:11 AM

    Could you provide the exact query you're using ?

  • PixelSlave

    PixelSlave March 20th, 2009 @ 06:32 AM

    I experienced the same problem, but I was able to fix the problem by changing Selector.patterns.id to /^#([\w-*:_.]+)(\b|$)/.

  • Jørn Holm

    Jørn Holm June 23rd, 2009 @ 02:04 PM

    If #559 https://prototype.lighthouseapp.com/projects/8886/tickets/559-safar... is fixed I belive this issue can be close.

    #559 prevents the use of selectorAPI (in any browser) for id's with "." or ":". (id="foo.bar" or id="foo:bar"

    Still an issue in 1.6.1 RC3.

  • quamis

    quamis July 7th, 2009 @ 04:35 PM

    Yes, the fix is working, this issue should be closed.

    As a side note, this bug also affects Firefox 3.5

  • Tobie Langel

    Tobie Langel July 23rd, 2009 @ 01:59 AM

    • State changed from “enhancement” to “duplicate”

    duplicate of #559

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 »

The Prototype JavaScript library.

Shared Ticket Bins


Referenced by