Bug Tracker

Opened 7 years ago

Closed 7 years ago

#13666 closed bug (wontfix)

.text(null) sets text to 'null'

Reported by: printercu@… Owned by: Rick Waldron
Priority: undecided Milestone: None
Component: unfiled Version: 1.9.1
Keywords: Cc:
Blocked by: Blocking:

Description

> $.fn.jquery
"1.9.1"

> $('<div>').text(null)
[<div>​null​</div>​]

> $('<div>').text(undefined)
[<div>​</div>​]

I think 2nd case should return same as the 3d.

Change History (9)

comment:2 Changed 7 years ago by Rick Waldron

Owner: set to Rick Waldron
Status: newassigned

Confirmed.

I'm concerned about breaking existing code, but I can't imagine why any code would ever rely on this. Before I fix it, I want to hear from dmethvin

comment:3 Changed 7 years ago by anonymous

under 1.7 both .text(undefined) & .text(null) works as getters.

1.7 it works the same as in example

I think think this behaviour just can reduce the code: .text(val) instead of .text(val
)

and also .html(null) works like .html()

comment:4 Changed 7 years ago by jaubourg

Looks like we genuinely forgot about this specific case.

comment:5 Changed 7 years ago by anonymous

sorry about previous comment)

under 1.7 both .text(undefined) & .text(null) work as getters.

in jq >=1.7 it works the same as in example

I think think this behaviour just can reduce the code: .text(val) instead of .text(val)

and also .html(null) works like .html("")

comment:6 Changed 7 years ago by anonymous

.text(val || "") instead of .text(val) i meant)

comment:7 in reply to:  4 Changed 7 years ago by gibson042

Replying to jaubourg:

Looks like we genuinely forgot about this specific case.

I'd further clarify that by saying that null and undefined have never been documented as valid input, though they were de facto getters before the fix for #5571 landed in 1.7.2. We currently no-op on the latter (explicitly correct) and set on the former (since it is invalid input, this behavior is our prerogative).

comment:8 Changed 7 years ago by gibson042

To make it extra clear, .text(null) and .text(undefined) were not even setters until 1.7.2, though .text(undefined) now explicitly no-ops.

comment:9 Changed 7 years ago by Rick Waldron

Resolution: wontfix
Status: assignedclosed

Closing as wont-fix, based on the information presented by gibson042

null is not a valid argument to text()

Note: See TracTickets for help on using tickets.