Skip to main content

Bug Tracker

Side navigation

#11901 closed bug (invalid)

Opened June 13, 2012 10:46AM UTC

Closed July 08, 2012 08:51AM UTC

JQuery opacity test is not exhaustive according to spec

Reported by: gary-1111 Owned by: gary-1111
Priority: undecided Milestone: None
Component: unfiled Version: 1.7.2
Keywords: Cc:
Blocked by: Blocking:
Description

On line 1417 of version 1.7.2 of JQuery there is a check to ensure that the browser is able to retrieve an opacity value set in some test HTML on line 1379.

The test HTML sets an opacity value of ".55" on a link element and the check tests "0.55" is returned when queried by JS.

The specification for "integers and real numbers" in CSS 2.1 "syntax and basic data types" (available here) states that:

''A <number> can either be an <integer>, or it can be zero or more digits followed by a dot (.) followed by one or more digits.''

As such it is perfectly valid for a browser to return ".55" in response to the check on line 1417. Currently if it does, the check fails and JQuery assumes the browser to be IE and "patches" all calls to set/get opacity. This causes a problem with the HTMLUnit browser (which does return ".55") as the patched set/get opacity logic attempts to invoke functions which are IE specific and causes an exception.

I understand that HTMLUnit is not a supported browser for the JQuery project but in terms of compatibility I think it would be better if the opacity check were updated to test according to spec.

Attachments (0)
Change History (6)

Changed June 14, 2012 12:54AM UTC by dmethvin comment:1

Any thoughts about a better test?

Changed June 14, 2012 08:07AM UTC by anonymous comment:2

Replying to [comment:1 dmethvin]:

Any thoughts about a better test?

The opacity check is simply updated to make the leading zero optional:

jquery-1.7.2.js, line 1417

opacity: /^0?.55/.test( a.style.opacity ),

All code where a returned CSS number is checked for some value should be updated to account for this.

Changed June 14, 2012 12:13PM UTC by dmethvin comment:3

owner: → gary-1111
status: newpending

Nope. We're setting the string ".5" and verifying that it has been processed by looking for a return value of "0.5". Try this on IE6/7/8, it would pass your test:

http://jsfiddle.net/Dw5nJ/

If you can come up with a simple solution *and test it* on jQuery's supported browsers we could include it. Perhaps it's easier to have HTMLUnit change their semantics though.

Changed June 14, 2012 12:34PM UTC by gary-1111 comment:4

status: pendingnew

This bug is logged against the 1.7.2 release of JQuery - not the latest code from Git (in which I can see the set/check values have been changed to ".5"/"0.5")

With this said the fix is the same; make the leading zero optional in the regex which tests the returned opacity value:

jquery-git.js, line 1347

opacity: /^0?.5/.test( a.style.opacity ),

This works for JQuery's supported browsers and ultimately makes the library more standards compliant and therefore robust.

Changed June 23, 2012 02:25PM UTC by dmethvin comment:5

status: newpending

Why do you say it works for jQuery's supported browsers? Did you try the test case on IE7 for example? This version makes it even clearer the change will break things.

http://jsfiddle.net/Dw5nJ/1/

Honestly, I have no problem with trying to fix this but we are not going to break a supported browser in order to solve a problem for an unsupported environment.

Changed July 08, 2012 08:51AM UTC by trac-o-bot comment:6

resolution: → invalid
status: pendingclosed

Because we get so many tickets, we often need to return them to the initial reporter for more information. If that person does not reply within 14 days, the ticket will automatically be closed, and that has happened in this case. If you still are interested in pursuing this issue, feel free to add a comment with the requested information and we will be happy to reopen the ticket if it is still valid. Thanks!