diff --git a/poi/src/main/java/org/apache/poi/hssf/record/RecordFactory.java b/poi/src/main/java/org/apache/poi/hssf/record/RecordFactory.java index 16f1a04d04..08b49f5be4 100644 --- a/poi/src/main/java/org/apache/poi/hssf/record/RecordFactory.java +++ b/poi/src/main/java/org/apache/poi/hssf/record/RecordFactory.java @@ -34,8 +34,8 @@ import org.apache.poi.util.RecordFormatException; public final class RecordFactory { private static final int NUM_RECORDS = 512; - // how many records we read at max by default (can be adjusted via IOUtils) - //increased to 5 million due to https://bz.apache.org/bugzilla/show_bug.cgi?id=65887 + // how many records we read at max by default (can be adjusted via the static setters) + // increased to 5 million due to https://bz.apache.org/bugzilla/show_bug.cgi?id=65887 private static final int DEFAULT_MAX_NUMBER_OF_RECORDS = 5_000_000; private static int MAX_NUMBER_OF_RECORDS = DEFAULT_MAX_NUMBER_OF_RECORDS; diff --git a/poi/src/main/java/org/apache/poi/hssf/record/RecordInputStream.java b/poi/src/main/java/org/apache/poi/hssf/record/RecordInputStream.java index 06420f394b..561768f32b 100644 --- a/poi/src/main/java/org/apache/poi/hssf/record/RecordInputStream.java +++ b/poi/src/main/java/org/apache/poi/hssf/record/RecordInputStream.java @@ -216,7 +216,8 @@ public final class RecordInputStream implements LittleEndianInput { _currentDataLength = _bhi.readDataSize(); if (_currentDataLength > MAX_RECORD_DATA_SIZE) { throw new RecordFormatException("The content of an excel record cannot exceed " - + MAX_RECORD_DATA_SIZE + " bytes"); + + MAX_RECORD_DATA_SIZE + " bytes, but had: " + _currentDataLength + + " for record with sid: " + _currentSid); } } diff --git a/poi/src/main/java/org/apache/poi/ss/formula/functions/TextFunction.java b/poi/src/main/java/org/apache/poi/ss/formula/functions/TextFunction.java index 518fe08e0c..5a2b613c93 100644 --- a/poi/src/main/java/org/apache/poi/ss/formula/functions/TextFunction.java +++ b/poi/src/main/java/org/apache/poi/ss/formula/functions/TextFunction.java @@ -108,12 +108,14 @@ public abstract class TextFunction implements Function { return new NumberEval(arg.length()); } }; + public static final Function LOWER = new SingleArgTextFunc() { @Override protected ValueEval evaluate(String arg) { return new StringEval(arg.toLowerCase(Locale.ROOT)); } }; + public static final Function UPPER = new SingleArgTextFunc() { @Override protected ValueEval evaluate(String arg) { @@ -246,13 +248,16 @@ public abstract class TextFunction implements Function { private static final class LeftRight extends Var1or2ArgFunction { private static final ValueEval DEFAULT_ARG1 = new NumberEval(1.0); private final boolean _isLeft; + protected LeftRight(boolean isLeft) { _isLeft = isLeft; } + @Override public ValueEval evaluate(int srcRowIndex, int srcColumnIndex, ValueEval arg0) { return evaluate(srcRowIndex, srcColumnIndex, arg0, DEFAULT_ARG1); } + @Override public ValueEval evaluate(int srcRowIndex, int srcColumnIndex, ValueEval arg0, ValueEval arg1) { @@ -369,7 +374,6 @@ public abstract class TextFunction implements Function { try { valueDouble = DateUtil.parseDateTime(evaluated); } catch (Exception ignored) { - valueDouble = null; } } } @@ -393,7 +397,7 @@ public abstract class TextFunction implements Function { * Using it instead of {@link OperandResolver#coerceValueToString(ValueEval)} in order to handle booleans differently. */ private String formatPatternValueEval2String(ValueEval ve) { - String format = null; + final String format; if (!(ve instanceof BoolEval) && (ve instanceof StringValueEval)) { StringValueEval sve = (StringValueEval) ve; format = sve.getStringValue(); @@ -414,6 +418,7 @@ public abstract class TextFunction implements Function { public SearchFind(boolean isCaseSensitive) { _isCaseSensitive = isCaseSensitive; } + @Override public ValueEval evaluate(int srcRowIndex, int srcColumnIndex, ValueEval arg0, ValueEval arg1) { try { @@ -424,6 +429,7 @@ public abstract class TextFunction implements Function { return e.getErrorEval(); } } + @Override public ValueEval evaluate(int srcRowIndex, int srcColumnIndex, ValueEval arg0, ValueEval arg1, ValueEval arg2) { @@ -440,6 +446,7 @@ public abstract class TextFunction implements Function { return e.getErrorEval(); } } + private ValueEval eval(String haystack, String needle, int startIndex) { int result; if (_isCaseSensitive) { @@ -454,6 +461,7 @@ public abstract class TextFunction implements Function { return new NumberEval(result + 1.); } } + /** * Implementation of the FIND() function.
* @@ -468,6 +476,7 @@ public abstract class TextFunction implements Function { * Author: Torstein Tauno Svendsen (torstei@officenet.no) */ public static final Function FIND = new SearchFind(true); + /** * Implementation of the FIND() function.
*
diff --git a/poi/src/main/java/org/apache/poi/ss/usermodel/DataFormatter.java b/poi/src/main/java/org/apache/poi/ss/usermodel/DataFormatter.java
index b3de0462b0..95b0243bce 100644
--- a/poi/src/main/java/org/apache/poi/ss/usermodel/DataFormatter.java
+++ b/poi/src/main/java/org/apache/poi/ss/usermodel/DataFormatter.java
@@ -380,7 +380,7 @@ public class DataFormatter {
// String formatStr = (i < formatBits.length) ? formatBits[i] : formatBits[0];
// this replace is done to fix https://bz.apache.org/bugzilla/show_bug.cgi?id=63211
- String formatStr = formatStrIn.replace("\\%", "\'%\'");
+ String formatStr = formatStrIn.replace("\\%", "'%'");
// Excel supports 2+ part conditional data formats, eg positive/negative/zero,
// or (>1000),(>0),(0),(negative). As Java doesn't handle these kinds
@@ -700,7 +700,7 @@ public class DataFormatter {
private String cleanFormatForNumber(String formatStrIn) {
// this replace is done to fix https://bz.apache.org/bugzilla/show_bug.cgi?id=63211
- String formatStr = formatStrIn.replace("\\%", "\'%\'");
+ String formatStr = formatStrIn.replace("\\%", "'%'");
StringBuilder sb = new StringBuilder(formatStr);
diff --git a/poi/src/test/java/org/apache/poi/hssf/record/TestRecordFactory.java b/poi/src/test/java/org/apache/poi/hssf/record/TestRecordFactory.java
index 26793e1930..56ad402776 100644
--- a/poi/src/test/java/org/apache/poi/hssf/record/TestRecordFactory.java
+++ b/poi/src/test/java/org/apache/poi/hssf/record/TestRecordFactory.java
@@ -19,7 +19,8 @@ package org.apache.poi.hssf.record;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import java.io.ByteArrayInputStream;
import java.io.IOException;
@@ -27,8 +28,10 @@ import java.io.InputStream;
import java.util.List;
import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
+import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.util.HexRead;
+import org.apache.poi.util.RecordFormatException;
import org.junit.jupiter.api.Test;
/**
@@ -178,11 +181,11 @@ final class TestRecordFactory {
List