Bug Tracker

Opened 14 years ago

Closed 12 years ago

Last modified 11 years ago

#4533 closed bug (invalid)

text(val) and new String

Reported by: kspeakman Owned by:
Priority: major Milestone: 1.4
Component: core Version: 1.3.2
Keywords: text(val) Cc:
Blocked by: Blocking:


text(val) fails if val is a Javascript String object. This is counter-intuitive, and hard to track down. The default error message when this happens is not meaningful. Firefox says "G is undefined". Chrome says "Uncaught TypeError: Cannot read property 'length' of undefined". Safari says "Undefined value". IE says "'length' is null or not an object".


Repro code follows and is also attached:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
	 	 <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script>
	 	 <input type="button" value="Crash!" onclick="$('#test').text(new String('Test2'));" />
	 	 <span id="test">Test</span>


Suggested fix follows. I haven't looked at the text(val) code, but in my imagination a fix would look something like this:

text: function(val) {
	 if (val.toString !== undefined) val = val.toString();

Attachments (1)

bug.jQuery.text.html (396 bytes) - added by kspeakman 14 years ago.
Demo page for the text(val) and Javascript String object bug.

Download all attachments as: .zip

Change History (3)

Changed 14 years ago by kspeakman

Attachment: bug.jQuery.text.html added

Demo page for the text(val) and Javascript String object bug.

comment:1 Changed 13 years ago by dmethvin

Related: #5319

comment:2 Changed 12 years ago by miketaylr

Resolution: invalid
Status: newclosed

.text() takes a string primitive as an argument (http://api.jquery.com/text/), rather than a string object.

Note: See TracTickets for help on using tickets.