Opened 9 years ago

Closed 9 years ago

#6947 closed feature (fixed)

Attempt to access private member of widget returns jQuery object

Reported by: wkmanire Owned by:
Priority: major Milestone: 1.9.0
Component: ui.widget Version: 1.8.9
Keywords: Cc:
Blocked by: Blocking:

Description

I'm submitting this as a bug, but I think this could be classified as an enhancement.

ui.widget's bridge method protects against calling pseudo-private methods that start with an underscore by immediately returning "this". In my opinion, it should instead throw an exception to inform the developer that the widget is not being used properly. I can see the potential for a hard to detect bug going into production code as a result of the current behavior.

// starting on line 73 of jquery.ui.widget.js
var isMethodCall = typeof options === "string",
  args = slice.call( arguments, 1 ),
  returnValue = this;

// then on line 83 returnValue remains "this"

// prevent calls to internal methods
if ( isMethodCall && options.charAt( 0 ) === "_" ) {
  // perhaps instead at this point $.error('jquery.ui.widget: Attempt to access private member ' + options);
  return returnValue;
}

Change History (5)

comment:1 Changed 9 years ago by Scott González

Priority: minormajor
Status: newopen
Type: bugfeature

We should treat this the same as non-existant methods. See #5972 for a related change.

comment:2 Changed 9 years ago by wkmanire

I just submitted a pull request for this. I goofed up and accidently copied another unit test on my first commit so there are actually two commits. The first commit has the fix, a unit test, and an erroneous copy paste. The second removes the erroneous copy paste.

1st: https://github.com/wkmanire/jquery-ui/tree/f331db7e7d57416b65954c88a6c8e7c007313f8f

2nd: https://github.com/wkmanire/jquery-ui/commit/42068d5b1e6ea89f2f10ae5dcb1fd1e2b4b9cc6a

comment:3 Changed 9 years ago by wkmanire

I took another stab at this according to scott.gonzalez's direction. Should I submit another pull request? I read the guidelines but I'm still not completely familiar with this process.

Here is the commit: https://github.com/wkmanire/jquery-ui/commit/ddb24adbe9a2648083614fcf1dbfd6880a54e93b

comment:4 Changed 9 years ago by wkmanire

Next pull request is ready. Attempts to execute private methods are treated the same as missing methods. Unit test code integrated into errors test.

Here is the commit for it: https://github.com/wkmanire/jquery-ui/commit/c94ec23b263464af3dfa4533eff45fc0d6fef954

comment:5 Changed 9 years ago by William Kevin Manire

Resolution: fixed
Status: openclosed

Widget: modified widget to throw exception on attempt to call private methods. Fixed #6947 - Attempt to access private member of widget returns jQuery object

Changeset: c94ec23b263464af3dfa4533eff45fc0d6fef954

Note: See TracTickets for help on using tickets.