Ticket #944 (closed defect: fixed)

Opened 4 years ago

Last modified 4 years ago

hasClass needs to be bulletproofed

Reported by: PaulReiber Owned by: MartinBudden
Priority: major Milestone: 2.5.1
Component: core Version:
Severity: high Keywords:
Cc:

Description

e.className is not always a string (for example, in svg it's an SVGAnimatedString)

SVGAnimatedString doesnt implement split, so it throws an error.

Change History

Changed 4 years ago by PaulReiber

I think all we need to add is a call to toString to fix this - i.e.:

function hasClass(e,className)
{
	if(e.className && e.className.toString().split(" ").indexOf(className) != -1) {
		return true;
	}
	return false;
}

Changed 4 years ago by FND

  • status changed from new to closed
  • resolution set to invalid

Since TiddlyWiki will include jQuery from v2.5, we will rely on that library for such  helper functions in the future.

However, I don't know whether jQuery supports the SVG use case - if not, this issue should be raised in the jQuery community, perhaps resulting in an optional jQuery plugin.

Thus marking this as INVALID for now.

Changed 4 years ago by EricShulman

  • status changed from closed to reopened
  • resolution invalid deleted
  • severity changed from undefined to high
  • milestone set to 2.5.1

This problem *is* valid... a fatal error *does* occur, under readily reproducible conditions.

Use of string methods directly on "e.className" occurs in several other core functions in addition hasClass()... and also assume that the className is always a string, which is apparently not the case for some kinds of elements (e.g., an SVG block) (which causes references to e.className.split() to throw errors)

A *future* plan to use JQuery's helper function is not a resolution of *this* problem... at least until the code has actually been patched in TW2.5.1 (or later).

Closing the ticket at this time just ignores the issue and makes it less likely that, when actually migrating to JQuery, proper attention will be paid to this issue to ensure that *all* instances of this problem are corrected.

Please leave this ticket open until the problem it is reporting has actually been resolved.

Changed 4 years ago by FND

  • owner changed from JeremyRuston to MartinBudden
  • status changed from reopened to new

Changed 4 years ago by MartinBudden

Eric, can you outline the conditions that cause the error to occur, so that this can be tested?

Changed 4 years ago by MartinBudden

  • milestone changed from 2.5.1 to 2.5.2

Changed 4 years ago by EricShulman

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

I've just re-tested 'in situ' using the latest nightly build: TW251A1 (build9510), and the problem appears to have been bypassed by using jQuery

function hasClass(e, className) {
    return jq(e).hasClass(className);
}

Changed 4 years ago by MartinBudden

  • milestone changed from 2.5.2 to 2.5.1
Note: See TracTickets for help on using tickets.