Ticket #276 (closed enhancement: fixed)

Opened 2 years ago

Last modified 18 months ago

Problem with Selector

Reported by: sschz@… Owned by: cederberg@…
Priority: normal Milestone: MochiKit 1.4
Component: component1 Version:
Severity: normal Keywords:
Cc:

Description

There is a problem when using the Selector object.

Description

Something like:

  var selector = new MochiKit.Selector.Selector('script[src="srcValue"]');
  var matches = selector.findElements(document.getElementsByTagName('head')[0]);

would work properly even if there are some script elements with no src attribute.

On the contrary, if doing:

  var selector = new MochiKit.Selector.Selector('script[src$="srcValue"]');
  var matches = selector.findElements(document.getElementsByTagName('head')[0]);

and there are some script elements with no src attribute, this would throw an error.

Proposed solution

It would be nice if, instead of doing

   conditions.push(value + '.substring(' + value + '.length - ' + attribute.value.length + ') == ' + repr(attribute.value));

at the Selector buildMatchExpression function, the existence of the property were taken into account or, if not, the selector 'script[src][src$="srcValue"]' were performed as a shortcut.

Change History

Changed 18 months ago by cederberg@…

  • owner changed from somebody to cederberg@…
  • status changed from new to assigned
  • milestone set to MochiKit 1.4

Thanks for the bug report. This is indeed an issue. I think I'll opt for adding an additional existence requirement as suggested.

Changed 18 months ago by cederberg@…

  • status changed from assigned to closed
  • resolution set to fixed

Fixed in r1404.

Note: See TracTickets for help on using tickets.