Bug Tracker

Opened 7 years ago

Closed 7 years ago

#11901 closed bug (invalid)

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.

Change History (6)

comment:1 Changed 7 years ago by dmethvin

Any thoughts about a better test?

comment:2 in reply to:  1 Changed 7 years ago by anonymous

Replying to 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.

comment:3 Changed 7 years ago by dmethvin

Owner: set to 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.

comment:4 Changed 7 years ago by gary-1111

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.

comment:5 Changed 7 years ago by dmethvin

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.

comment:6 Changed 7 years ago by trac-o-bot

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!

Note: See TracTickets for help on using tickets.