Skip to main content

Bug Tracker

Side navigation

#13666 closed bug (wontfix)

Opened March 26, 2013 01:06PM UTC

Closed March 27, 2013 01:40PM UTC

.text(null) sets text to 'null'

Reported by: printercu@gmail.com Owned by: rwaldron
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.

Attachments (0)
Change History (9)

Changed March 26, 2013 03:40PM UTC by anonymous comment:1

Changed March 26, 2013 03:47PM UTC by rwaldron comment:2

owner: → rwaldron
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

Changed March 26, 2013 05:34PM UTC by anonymous comment:3

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('')

Changed March 26, 2013 05:38PM UTC by jaubourg comment:4

Looks like we genuinely forgot about this specific case.

Changed March 26, 2013 05:39PM UTC by anonymous comment:5

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("")

Changed March 26, 2013 05:42PM UTC by anonymous comment:6

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

Changed March 26, 2013 06:09PM UTC by gibson042 comment:7

Replying to [comment:4 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).

Changed March 26, 2013 06:18PM UTC by gibson042 comment:8

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.

Changed March 27, 2013 01:40PM UTC by rwaldron comment:9

resolution: → wontfix
status: assignedclosed

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

null is not a valid argument to text()