Author: cbrisson
Date: Mon Dec  9 20:44:40 2019
New Revision: 1871101

URL: http://svn.apache.org/viewvc?rev=1871101&view=rev
Log:
[view-tools] JsonTool: bugfix: properly extract mime type from content type 
when followed by a charset

Modified:
    
velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/JsonTool.java

Modified: 
velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/JsonTool.java
URL: 
http://svn.apache.org/viewvc/velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/JsonTool.java?rev=1871101&r1=1871100&r2=1871101&view=diff
==============================================================================
--- 
velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/JsonTool.java
 (original)
+++ 
velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/JsonTool.java
 Mon Dec  9 20:44:40 2019
@@ -73,6 +73,24 @@ public class JsonTool extends org.apache
     }
 
     /**
+     * Check if a given content type is of JSON type
+     * @param contentType content type
+     * @return whether given content type is of JSON type
+     */
+    protected static boolean isJsonContentType(String contentType)
+    {
+        if (contentType != null)
+        {
+            int sep = contentType.indexOf(';');
+            String mimeType = sep == -1
+                ? contentType
+                : contentType.substring(0, sep).trim();
+            return isJsonMimeType(mimeType);
+        }
+        return false;
+    }
+
+    /**
      * Configuration. Parses request body if appropriate.
      * @param parser configuration values
      */
@@ -82,7 +100,7 @@ public class JsonTool extends org.apache
         if (root() == null)
         {
             ServletRequest request = 
(ServletRequest)parser.get(ViewContext.REQUEST);
-            if (request.getContentLength() > 0 && 
isJsonMimeType(request.getContentType()))
+            if (request.getContentLength() > 0 && 
isJsonContentType(request.getContentType()))
             {
                 try
                 {


Reply via email to