Issue with Malformed URI Handling

[ad_1]

Hello! WP Custom Admin Interface plugin fails to show the menu to edit in the “Edit Admin Menu” tab. The console logs indicate an issue with malformed URIs during the decoding process.

Console Error:

Uncaught URIError: URI malformed
at decodeURIComponent ()
at renderAdminMenuManager (options-page-admin-menu.js?ver=7.36:223:54)
at HTMLDocument. (options-page-admin-menu.js?ver=7.36:242:5)
at e (load-scripts.php?c=1&load%5Bchunk_0%5D=jquery-core,jquery-migrate,utils,wp-polyfill-inert,regenerator-runtime,wp-polyfill,wp-hooks&ver=6.5.4:2:27028)
at t (load-scripts.php?c=1&load%5Bchunk_0%5D=jquery-core,jquery-migrate,utils,wp-polyfill-inert,regenerator-runtime,wp-polyfill,wp-hooks&ver=6.5.4:2:27330)

Analysis:

It seems that the error URIError: URI malformed occurs when decodeURIComponent is called on a string that is not a valid URI. The specific line causing the issue is:

223:var subLevelMenuThirdValue = decodeURIComponent(subLevelObject[key][3]);

Upon investigation, it was found that some values being passed to decodeURIComponent are not URIs but plain text or HTML, such as:

Upgrade For 80% Off! <a href="https://wpmudev.com/project/wp-defender/?utm_source=defender&amp;utm_medium=plugin&amp;utm_campaign=defender_submenu_upsell" target="_blank">Upgrade For 80% Off!</a>

In this case the issue is caused by additional submenu promo-link from WPMU Defender plugin.

Proposed quick-fix:

  1. Add helper functions:
  • isValidURI: To check if a string is a valid URI.
  • safeDecodeURIComponent: To safely decode URIs, handling errors gracefully.

function isValidURI(uri) { return uri.startsWith('http://') || uri.startsWith('https://') || uri.startsWith('ftp://') || uri.startsWith('mailto:'); } function safeDecodeURIComponent(uri) { if (typeof uri !== 'string' || !isValidURI(uri)) { return uri; // Return the original string if it is not a valid URI } try { return decodeURIComponent(uri); } catch (e) { return uri; // Handle the error gracefully } }

Further analysis and final solution required.

Regards!

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer