|
76 | 76 | import java.util.Collection; |
77 | 77 | import java.util.Collections; |
78 | 78 | import java.util.HashMap; |
| 79 | +import java.util.LinkedHashMap; |
79 | 80 | import java.util.List; |
80 | 81 | import java.util.Map; |
81 | 82 | import java.util.function.Predicate; |
@@ -185,51 +186,26 @@ public static PropertyValues getPropertyValuesForFormBinding(PropertyValues pvs, |
185 | 186 | return ret; |
186 | 187 | } |
187 | 188 |
|
188 | | - static final String FORM_DATE_ENCODED_PARAM = "formDataEncoded"; |
189 | 189 |
|
190 | | - /** |
191 | | - * When a double quote is encountered in a multipart/form-data context, it is encoded as %22 using URL-encoding by browsers. |
192 | | - * This process replaces the double quote with its hexadecimal equivalent in a URL-safe format, preventing it from being misinterpreted as the end of a value or a boundary. |
193 | | - * The consequence of such encoding is we can't distinguish '"' from the actual '%22' in parameter name. |
194 | | - * As a workaround, a client-side util `encodeFormDataQuote` is used to convert %22 to %2522 and " to %22 explicitly, while passing in an additional param formDataEncoded=true. |
195 | | - * This class converts those encoded param names back to its decoded form during PropertyValues binding. |
196 | | - * See Issue 52827, 52925 and 52119 for more information. |
197 | | - */ |
| 190 | + /// Some characters can be mishandled by the browser in multipart/formdata requests (e.g. doublequote and backslask). |
| 191 | + /// We support an encoding from fields to avoid these characters, see {@link PageFlowUtil#encodeFormName} and {@link PageFlowUtil#decodeFormName}. |
198 | 192 | static public class ViewActionParameterPropertyValues extends ServletRequestParameterPropertyValues |
199 | 193 | { |
200 | | - |
201 | 194 | public ViewActionParameterPropertyValues(ServletRequest request) { |
202 | 195 | this(request, null, null); |
203 | 196 | } |
204 | 197 |
|
205 | 198 | public ViewActionParameterPropertyValues(ServletRequest request, @Nullable String prefix, @Nullable String prefixSeparator) |
206 | 199 | { |
207 | 200 | super(request, prefix, prefixSeparator); |
208 | | - if (isFormDataEncoded()) |
209 | | - { |
210 | | - for (int i = 0; i < getPropertyValues().length; i++) |
211 | | - { |
212 | | - PropertyValue formDataPropValue = getPropertyValues()[i]; |
213 | | - String propValueName = formDataPropValue.getName(); |
214 | | - String decoded = PageFlowUtil.decodeQuoteEncodedFormDataKey(propValueName); |
215 | | - if (!propValueName.equals(decoded)) |
216 | | - setPropertyValueAt(new PropertyValue(decoded, formDataPropValue.getValue()), i); |
217 | | - } |
218 | | - } |
219 | | - } |
220 | | - |
221 | | - private boolean isFormDataEncoded() |
222 | | - { |
223 | | - PropertyValue formDataPropValue = getPropertyValue(FORM_DATE_ENCODED_PARAM); |
224 | | - if (formDataPropValue != null) |
| 201 | + for (int i = 0; i < getPropertyValues().length; i++) |
225 | 202 | { |
226 | | - Object v = formDataPropValue.getValue(); |
227 | | - String formDataPropValueStr = v == null ? null : String.valueOf(v); |
228 | | - if (StringUtils.isNotBlank(formDataPropValueStr)) |
229 | | - return (Boolean) ConvertUtils.convert(formDataPropValueStr, Boolean.class); |
| 203 | + PropertyValue formDataPropValue = getPropertyValues()[i]; |
| 204 | + String propValueName = formDataPropValue.getName(); |
| 205 | + String decoded = PageFlowUtil.decodeFormName(propValueName); |
| 206 | + if (!propValueName.equals(decoded)) |
| 207 | + setPropertyValueAt(new PropertyValue(decoded, formDataPropValue.getValue()), i); |
230 | 208 | } |
231 | | - |
232 | | - return false; |
233 | 209 | } |
234 | 210 | } |
235 | 211 |
|
@@ -725,9 +701,7 @@ public <T> T convertIfNecessary(Object value, Class<T> requiredType, MethodParam |
725 | 701 | */ |
726 | 702 | protected Map<String, MultipartFile> getFileMap() |
727 | 703 | { |
728 | | - if (getViewContext().getRequest() instanceof MultipartHttpServletRequest) |
729 | | - return ((MultipartHttpServletRequest)getViewContext().getRequest()).getFileMap(); |
730 | | - return Collections.emptyMap(); |
| 704 | + return PageFlowUtil.getFileMap(getViewContext().getRequest()); |
731 | 705 | } |
732 | 706 |
|
733 | 707 | protected List<AttachmentFile> getAttachmentFileList() |
|
0 commit comments