pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1837747 - in /pdfbox/branches/2.0/pdfbox/src: main/java/org/apache/pdfbox/cos/COSFloat.java test/java/org/apache/pdfbox/cos/TestCOSFloat.java
Date Thu, 09 Aug 2018 17:45:36 GMT
Author: tilman
Date: Thu Aug  9 17:45:36 2018
New Revision: 1837747

URL: http://svn.apache.org/viewvc?rev=1837747&view=rev
Log:
PDFBOX-4289: remove double negative

Modified:
    pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/cos/COSFloat.java
    pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/cos/TestCOSFloat.java

Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/cos/COSFloat.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/cos/COSFloat.java?rev=1837747&r1=1837746&r2=1837747&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/cos/COSFloat.java (original)
+++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/cos/COSFloat.java Thu Aug 
9 17:45:36 2018
@@ -61,26 +61,31 @@ public class COSFloat extends COSNumber
         }
         catch( NumberFormatException e )
         {
-            if (aFloat.matches("^0\\.0*\\-\\d+"))
+            if (aFloat.startsWith("--"))
+            {
+                // PDFBOX-4289 has --16.33
+                valueAsString = aFloat.substring(1);
+            }
+            else if (aFloat.matches("^0\\.0*\\-\\d+"))
             {
                 // PDFBOX-2990 has 0.00000-33917698
                 // PDFBOX-3369 has 0.00-35095424
                 // PDFBOX-3500 has 0.-262
-                try
-                {
-                    valueAsString = "-" + valueAsString.replaceFirst("\\-", "");
-                    value = new BigDecimal(valueAsString);
-                    checkMinMaxValues();
-                }
-                catch (NumberFormatException e2)
-                {
-                    throw new IOException("Error expected floating point number actual='"
+ aFloat + "'", e2);
-                }
+                valueAsString = "-" + valueAsString.replaceFirst("\\-", "");
             }
             else
             {
                 throw new IOException("Error expected floating point number actual='" + aFloat
+ "'", e);
             }
+            try
+            {
+                value = new BigDecimal(valueAsString);
+                checkMinMaxValues();
+            }
+            catch (NumberFormatException e2)
+            {
+                throw new IOException("Error expected floating point number actual='" + aFloat
+ "'", e2);
+            }
         }
     }
     

Modified: pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/cos/TestCOSFloat.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/cos/TestCOSFloat.java?rev=1837747&r1=1837746&r2=1837747&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/cos/TestCOSFloat.java (original)
+++ pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/cos/TestCOSFloat.java Thu Aug
 9 17:45:36 2018
@@ -300,6 +300,13 @@ public class TestCOSFloat extends TestCO
         writePDFTester.runTest(0.000000000000000000000000000000001f);
     }
 
+    public void testDoubleNegative() throws IOException
+    {
+        // PDFBOX-4289
+        COSFloat cosFloat = new COSFloat("--16.33");
+        assertEquals(-16.33f, cosFloat.floatValue());
+    }
+
     private String floatToString(float value)
     {
         // use a BigDecimal as intermediate state to avoid 



Mime
View raw message