Bug Tracker

Opened 11 years ago

Closed 11 years ago

#11459 closed bug (invalid)

charset attribute of script tag lost when insert html string with .html()

Reported by: zeratul1986 Owned by: zeratul1986
Priority: undecided Milestone: None
Component: unfiled Version: 1.7.1
Keywords: Cc:
Blocked by: Blocking:


The .html() call does not handle a script tag with charset attribute correctly if the value of charset is not 'utf-8'.

A minimal test case below:

var html = '<script src="http://domain.com/sample.js" charset="gb2312"></script>';
$( 'body' ).html( html );

The script file "sample.js" was saved with charset "gb2312". The content should like this.

$( 'body' ).append( '<p>script loaded. 中文</p>' );

I ran into the source code of jQuery and found that it missed the charset attribute in the 'evalScript' function.

It can be fixed at line 6425 of jquery-1.7.1.js

  url: elem.src,
  scriptCharset: elem.charset, // handle the charset attribute
  async: false,
  dataType: "script"


Change History (2)

comment:1 Changed 11 years ago by sindresorhus

Owner: set to zeratul1986
Status: newpending

Thanks for taking the time to contribute to the jQuery project! Please provide a complete reduced test case on jsFiddle to help us assess your ticket.

Additionally, be sure to test against the jQuery Edge version to ensure the issue still exists. To get you started, use this boilerplate: http://jsfiddle.net/FrKyN/ Open the link and click to "Fork" (in the top menu) to get started.

comment:2 Changed 11 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.