Clean up POST keys containing square brackets, allows for regex ranges in routes (fixes #776)

This commit is contained in:
Djamil Legato
2016-09-15 12:57:28 -07:00
parent 0512a7f4f6
commit aba43374de
5 changed files with 39 additions and 16 deletions

View File

@@ -4,6 +4,7 @@
1. [](#bugfix)
* Fix [#1034](https://github.com/getgrav/grav/issues/1034) redirect of page creation procedure when system.home.hide_in_urls is enabled
* Media (Page): Do not extend parent metehod for sending files since Safari and IE API for FormData dont implement `delete` ([#772](https://github.com/getgrav/grav-plugin-admin/issues/772))
* Clean up POST keys containing square brackets, allows for regex ranges in routes ([#776](https://github.com/getgrav/grav-plugin-admin/issues/776))
# v1.2.2
## 09/08/2016

View File

@@ -2490,6 +2490,8 @@ class AdminController
unset($post['_json']);
}
$post = $this->cleanDataKeys($post);
return $post;
}
@@ -2701,4 +2703,21 @@ class AdminController
return $files;
}
protected function cleanDataKeys($source = []){
$out = [];
if (is_array($source)) {
foreach($source as $key => $value){
$key = str_replace('%5B', '[', str_replace('%5D', ']', $key));
if (is_array($value)) {
$out[$key] = $this->cleanDataKeys($value);
} else{
$out[$key] = $value;
}
}
}
return $out;
}
}

View File

@@ -96,7 +96,9 @@ export default class ArrayField {
let keyElement = type === 'key' ? element : element.siblings('[data-grav-array-type="key"]:first');
let valueElement = type === 'value' ? element : element.siblings('[data-grav-array-type="value"]:first');
let name = `${template.getName()}[${!template.isValueOnly() ? keyElement.val() : this.getIndexFor(element)}]`;
let escaped_name = !template.isValueOnly() ? keyElement.val() : this.getIndexFor(element);
escaped_name = escaped_name.replace(/\[/g, '%5B').replace(/]/g, '%5D');
let name = `${template.getName()}[${escaped_name}]`;
valueElement.attr('name', !valueElement.val() ? template.getName() : name);
this.refreshNames(template);

File diff suppressed because one or more lines are too long

View File

@@ -15,6 +15,7 @@
{% if key == '0' and text == '' %}
{% set key = '' %}
{% endif %}
{% set key = key|replace({'%5B': '[', '%5D': ']'}) %}
<input
data-grav-array-type="key"