gocodebox / lifterlms

LifterLMS, a WordPress LMS Solution: Easily create, sell, and protect engaging online courses.
https://lifterlms.com
GNU General Public License v3.0
182 stars 135 forks source link

Depreciated use of mb_convert_encoding() #2672

Open brianhogg opened 5 months ago

brianhogg commented 5 months ago

Reproduction Steps

  1. Enable debug/warning output
  2. Embed a video in a lesson
  3. View HTML of the wrapper (ie. with class llms-video-wrapper)

Expected Behavior

No warnings/errors shown

Actual Behavior

Depreciated:  mb_convert_encoding(): Handling HTML entities via mbstring is deprecated; use htmlspecialchars, htmlentities, or mb_encode_numericentity/mb_decode_numericentity instead in ...plugins/lifterlms/includes/class-llms-dom-document.php on line 136

This issue has be recreated:

brianhogg commented 5 months ago

From this post, the alternative is to use utf8_decode https://stackoverflow.com/questions/11974008/alternative-to-mb-convert-encoding-with-html-entities-charset. However utf8_decode is also depreciated, and the alternative suggested is to use mb_convert_encoding()...

brianhogg commented 5 months ago

This should work:

htmlspecialchars_decode( htmlentities( $this->source, ENT_COMPAT, 'UTF-8'), ENT_COMPAT);
brianhogg commented 3 months ago

htmlspecialchars_decode( htmlentities( $this->source ) ) (or with flags in the comment above) doesn't work for all the cases in test_llms_get_dom_document(). Not sure what a reliable alternative is.

brianhogg commented 2 months ago

Created a custom one that does pass all the tests around the encoding, but some other PHPUnit tests are failing. Switched PR to draft.