Skip to content

Commit

Permalink
Recipe Search Bug Fix for Special Characters & Spaces
Browse files Browse the repository at this point in the history
Also a memory improvements when loading the recipe card which loads recipes to be selected from a select field.
  • Loading branch information
XjSv committed Jan 13, 2025
1 parent c5dbd6d commit c5a6347
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 30 deletions.
24 changes: 13 additions & 11 deletions assets/js/cooked-functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,20 +117,20 @@ var cooked_loading = false;

// Get form values
const formValues = {
category: $(this).find('[name="cp_recipe_category"]').val() || '',
method: $(this).find('[name="cp_recipe_cooking_method"]').val() || '',
cuisine: $(this).find('[name="cp_recipe_cuisine"]').val() || '',
tags: $(this).find('[name="cp_recipe_tags"]').val() || '',
diet: $(this).find('[name="cp_recipe_diet"]').val() || '',
search: $(this).find('[name="cooked_search_s"]').val() || '',
sort: $(this).find('[name="cooked_browse_sort_by"]').val() || 'date_desc',
category: wp.sanitize.stripTags($(this).find('[name="cp_recipe_category"]').val() || ''),
method: wp.sanitize.stripTags($(this).find('[name="cp_recipe_cooking_method"]').val() || ''),
cuisine: wp.sanitize.stripTags($(this).find('[name="cp_recipe_cuisine"]').val() || ''),
tags: wp.sanitize.stripTags($(this).find('[name="cp_recipe_tags"]').val() || ''),
diet: wp.sanitize.stripTags($(this).find('[name="cp_recipe_diet"]').val() || ''),
search: wp.sanitize.stripTags($(this).find('[name="cooked_search_s"]').val() || ''),
sort: wp.sanitize.stripTags($(this).find('[name="cooked_browse_sort_by"]').val() || 'date_desc'),
};

// Create URL segments
// Create URL segments with proper encoding
const urlSegments = [];
urlSegments.push(cooked_js_vars.browse_recipes_slug);
urlSegments.push(encodeURIComponent(cooked_js_vars.browse_recipes_slug));

// Add taxonomy segments
// Add taxonomy segments with improved encoding
const taxonomyFields = [
{ value: formValues.category, prefix: cooked_js_vars.recipe_category_slug },
{ value: formValues.method, prefix: cooked_js_vars.recipe_cooking_method_slug },
Expand All @@ -141,7 +141,9 @@ var cooked_loading = false;

taxonomyFields.forEach(field => {
if (field.value) {
urlSegments.push(`${field.prefix}/${encodeURIComponent(field.value)}`);
const safePrefix = encodeURIComponent(field.prefix);
const safeValue = encodeURIComponent(field.value);
urlSegments.push(`${safePrefix}/${safeValue}`);
}
});

Expand Down
2 changes: 1 addition & 1 deletion assets/js/cooked-functions.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit c5a6347

Please sign in to comment.