From 8cd113ba9ef5e2f3dfe9ef3fcefdbde0000e778a Mon Sep 17 00:00:00 2001 From: Yegor Kozlov Date: Thu, 4 Oct 2012 11:52:20 +0000 Subject: [PATCH] Bugzilla 52211 - avoid unnessary re-coverting content types to US-ASCII, it can cause exceptions on ibm mainframes git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1394001 13f79535-47bb-0310-9956-ffa450edef68 --- src/documentation/content/xdocs/status.xml | 1 + .../poi/openxml4j/opc/internal/ContentType.java | 11 +---------- .../org/apache/poi/openxml4j/opc/TestContentType.java | 4 +++- 3 files changed, 5 insertions(+), 11 deletions(-) diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index 0d13e0b3c4..90fdb8838c 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -34,6 +34,7 @@ + 52211 - avoid unnessary re-coverting content types to US-ASCII, it can cause exceptions on ibm mainframes 53568 - Set shapes anchors in XSSF when reading from existing drawings HSSFOptimiser will now also tidy away un-used cell styles, in addition to duplicate styles 53493 - Fixed memory and temporary file leak in SXSSF diff --git a/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/ContentType.java b/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/ContentType.java index ecf45af549..4d4c9283c2 100644 --- a/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/ContentType.java +++ b/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/ContentType.java @@ -134,16 +134,7 @@ public final class ContentType { * If the specified content type is not valid with RFC 2616. */ public ContentType(String contentType) throws InvalidFormatException { - // Conversion en US-ASCII - String contentTypeASCII = null; - try { - contentTypeASCII = new String(contentType.getBytes(), "US-ASCII"); - } catch (UnsupportedEncodingException e) { - throw new InvalidFormatException( - "The specified content type is not an ASCII value."); - } - - Matcher mMediaType = patternMediaType.matcher(contentTypeASCII); + Matcher mMediaType = patternMediaType.matcher(contentType); if (!mMediaType.matches()) throw new InvalidFormatException( "The specified content type '" diff --git a/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestContentType.java b/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestContentType.java index 257f4015de..ab2d6aa716 100644 --- a/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestContentType.java +++ b/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestContentType.java @@ -85,7 +85,9 @@ public final class TestContentType extends TestCase { */ public void testContentTypeParameterFailure() { String[] contentTypesToTest = new String[] { "mail/toto;titi=tata", - "text/xml;a=b;c=d", "mail/toto;\"titi=tata\"" }; + "text/xml;a=b;c=d", "mail/toto;\"titi=tata\"", + "text/\u0080" // characters above ASCII are not allowed + }; for (int i = 0; i < contentTypesToTest.length; ++i) { try { new ContentType(contentTypesToTest[i]); -- 2.39.5