Skip to content

Commit 16225c5

Browse files
authored
Upgrade guide: Use the new Migrate API to enable the self-closed-tags patch
Advise to use the new API: ```js jQuery.migrateEnablePatches( "self-closed-tags" ); ``` instead of the deprecated one: ```js jQuery.UNSAFE_restoreLegacyHtmlPrefilter(); ``` Also, fix some grammar mistakes & typos. Closes gh-224
1 parent b02547d commit 16225c5

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

pages/upgrade-guide/3.5.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66

77
### A workaround
88

9-
If you want to upgrade to jQuery 3.5.0 or newer and don't have time to deal with breaking changes at the moment and you use jQuery Migrate 3.2.0 or newer, you can revert to the previous behavior by invoking:
9+
If you want to upgrade to jQuery 3.5.0 or newer and don't have time to deal with breaking changes at the moment, and you use jQuery Migrate 3.4.0 or newer, you can revert to the previous behavior by invoking:
1010
```js
11-
jQuery.UNSAFE_restoreLegacyHtmlPrefilter();
11+
jQuery.migrateEnablePatches( "self-closed-tags" );
1212
```
1313

14-
jQuery Migrate 3.3.0 or newer logs warnings for all input that's affected by this change, regardless of whether the `jQuery.UNSAFE_restoreLegacyHtmlPrefilter()` method was called or not. **Note**: if you overwrite `jQuery.htmlPrefilter` manually, you'll lose those warnings!
14+
As long as this method has been called, jQuery Migrate 3.4.0 or newer logs warnings for all input that's affected by this change. **Note**: if you overwrite `jQuery.htmlPrefilter` manually, you'll lose those warnings!
1515

1616
If you don't use jQuery Migrate, don't add it just for this one workaround. Instead, you can revert to the previous behavior by redefining `jQuery.htmlPrefilter` after loading jQuery:
1717
```js
@@ -21,7 +21,7 @@ jQuery.htmlPrefilter = function( html ) {
2121
};
2222
```
2323

24-
Note that if you do this, you lose the jQuery 3.5.0 security fix and you have to be more careful with what HTML you pass to jQuery manipulation methods; regular HTML sanitizing will not be enough. Some security libraries have special sanitization settings for jQuery. For example, [DOMPurify](https://github.com/cure53/DOMPurify) has a `SAFE_FOR_JQUERY` flag:
24+
Note that if you do this, you lose the jQuery 3.5.0 security fix, and you have to be more careful with what HTML you pass to jQuery manipulation methods; regular HTML sanitizing will not be enough. Some security libraries have special sanitization settings for jQuery. For example, [DOMPurify](https://github.com/cure53/DOMPurify/tree/2.0.17#can-i-configure-dompurify) used to support the `SAFE_FOR_JQUERY` flag in versions `2.0.17` or older:
2525
```js
2626
var sanitizedHtml = DOMPurify.sanitize( unsafeHtml, { SAFE_FOR_JQUERY: true } );
2727
elem.html( sanitizedHtml );
@@ -49,7 +49,7 @@ In jQuery 3.5.0, the `jQuery.htmlPrefilter` method always returns its argument u
4949

5050
To avoid this, don't use self-closing tags for tags that may have content unless your page runs in XHTML mode. Make sure you're sending a correct mime type: `application/xhtml+xml`; otherwise, your page will really run in HTML mode.
5151

52-
If you're writing a library and you want it to work both in HTML & XHTML modes, remember to use self-closing tags for empty elements, i.e. ones that don't have closing tags in HTML. For example, instead of:
52+
If you're writing a library, and you want it to work both in HTML & XHTML modes, remember to use self-closing tags for empty elements, i.e. ones that don't have closing tags in HTML. For example, instead of:
5353
```js
5454
jQuery( "<div/><img/>" );
5555
```
@@ -62,4 +62,4 @@ One popular input that still works in jQuery 3.5.0 or newer is the one with a si
6262
```js
6363
jQuery( "<div class='yellow' />" );
6464
```
65-
This is becuse it's XHTML-compliant and in HTML the parser first changes it to just the opening tag: `<div class='yellow'>` but then immediately auto-closes it as it reaches the end of input.
65+
This is because it's XHTML-compliant and in HTML the parser first changes it to just the opening tag: `<div class='yellow'>` but then immediately auto-closes it as it reaches the end of input.

0 commit comments

Comments
 (0)