mattmilburn / strapi-plugin-menus

A plugin for Strapi CMS to customize the structure of menus and menu items.
MIT License
112 stars 28 forks source link

Change url regex to allow :variables #110

Closed WeslleyNasRocha closed 8 months ago

WeslleyNasRocha commented 1 year ago

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch strapi-plugin-menus@1.4.1 for the project I'm working on.

What i'm trying to do is use a pattern to replace for variables in my application, now we use the pattern of :variable but the plugin doesn't allow this kind of character.

Here is the diff that solved my problem:

diff --git a/node_modules/strapi-plugin-menus/admin/src/constants.js b/node_modules/strapi-plugin-menus/admin/src/constants.js
index 29be819..2e9110b 100644
--- a/node_modules/strapi-plugin-menus/admin/src/constants.js
+++ b/node_modules/strapi-plugin-menus/admin/src/constants.js
@@ -14,15 +14,15 @@ export const URL_ABSOLUTE_REGEX = new RegExp(
   '^(https?:\\/\\/)?'+
   '((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|'+
   '((\\d{1,3}\\.){3}\\d{1,3}))'+
-  '(\\:\\d+)?(\\/[-a-z\\d%_.~+@]*)*'+
-  '(\\?[-a-z\\d%_.~+@;&=]*)?'+
+  '(\\:\\d+)?(\\/[-a-z\\d%_:.~+@]*)*'+
+  '(\\?[-a-z\\d%_:.~+@;&=]*)?'+
   '(\\#[-a-z\\d_]*)?$',
   'i'
 );

 export const URL_RELATIVE_REGEX = new RegExp(
-  '^(\\/[-a-z\\d%_.~+@]*)*'+
-  '(\\?[-a-z\\d%_.~+@;&=]*)?'+
+  '^(\\/[-a-z\\d%_:.~+@]*)*'+
+  '(\\?[-a-z\\d%_:.~+@;&=]*)?'+
   '(\\#[-a-z\\d_]*)?$',
   'i'
 );
diff --git a/node_modules/strapi-plugin-menus/admin/src/pages/EditView/form-layout.js b/node_modules/strapi-plugin-menus/admin/src/pages/EditView/form-layout.js
index f348482..f92be31 100644
--- a/node_modules/strapi-plugin-menus/admin/src/pages/EditView/form-layout.js
+++ b/node_modules/strapi-plugin-menus/admin/src/pages/EditView/form-layout.js
@@ -61,6 +61,7 @@ const menuItem = [
         id: getTrad( 'form.label.url' ),
         defaultMessage: 'URL',
       },
+      description: 'URL of the menu item. If the URL is external, please add http:// or https://. For parameters, please use the following format: /:param?anotherParam=:anotherParam',
       name: 'url',
       type: 'text',
     },

This issue body was partially generated by patch-package.

mattmilburn commented 8 months ago

Hi again @WeslleyNasRocha This is now updated in the latest version 1.6.1 of the plugin to allow : characters in URLs 🎉