Skip to content

Commit 5534b36

Browse files
committed
Default input tags with invalid types.
DEVSIX-2753
1 parent 191a7df commit 5534b36

File tree

6 files changed

+73
-3
lines changed

6 files changed

+73
-3
lines changed

src/main/java/com/itextpdf/html2pdf/LogMessageConstant.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ public final class LogMessageConstant {
7272
/** The Constant INPUT_SUPPORTS_ONLY_POINT_WIDTH. */
7373
@Deprecated
7474
public static final String INPUT_SUPPORTS_ONLY_POINT_WIDTH = "Input field supports only point width";
75+
/** The Constant INPUT_TYPE_IS_INVALID. */
76+
public static final String INPUT_TYPE_IS_INVALID = "Input type {0} is invalid. The default text type will be used instead.";
7577
/** The Constant INPUT_TYPE_IS_NOT_SUPPORTED. */
7678
public static final String INPUT_TYPE_IS_NOT_SUPPORTED = "Input type {0} is not supported";
7779
/** The Constant INVALID_CSS_PROPERTY_DECLARATION. */

src/main/java/com/itextpdf/html2pdf/attach/impl/tags/InputTagWorker.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,13 @@ public class InputTagWorker implements ITagWorker, IDisplayAware {
8484
*/
8585
public InputTagWorker(IElementNode element, ProcessorContext context) {
8686
String inputType = element.getAttribute(AttributeConstants.TYPE);
87+
if (!AttributeConstants.INPUT_TYPE_VALUES.contains(inputType)) {
88+
if (null != inputType && 0 != inputType.length()) {
89+
Logger logger = LoggerFactory.getLogger(InputTagWorker.class);
90+
logger.warn(MessageFormatUtil.format(LogMessageConstant.INPUT_TYPE_IS_INVALID, inputType));
91+
}
92+
inputType = AttributeConstants.TEXT;
93+
}
8794
String value = element.getAttribute(AttributeConstants.VALUE);
8895
String name = context.getFormFieldNameResolver().resolveFormName(element.getAttribute(AttributeConstants.NAME));
8996
// Default input type is text

src/main/java/com/itextpdf/html2pdf/html/AttributeConstants.java

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ This file is part of the iText (R) project.
4444

4545
import com.itextpdf.styledxmlparser.CommonAttributeConstants;
4646

47+
import java.util.Arrays;
48+
import java.util.Collections;
49+
import java.util.HashSet;
50+
import java.util.Set;
51+
4752
/**
4853
* Class that bundles a series of attribute constants.
4954
*/
@@ -218,15 +223,33 @@ private AttributeConstants() {
218223
/** The Constant CHECKED. */
219224
public static final String CHECKED = "checked";
220225

226+
/** The Constant DATE. */
227+
public static final String DATE = "date";
228+
229+
/** The Constant DATETIME. */
230+
public static final String DATETIME = "datetime";
231+
232+
/** The Constant DATETIME_LOCAL. */
233+
public static final String DATETIME_LOCAL = "datetime_local";
234+
221235
/** The Constant EMAIL. */
222236
public static final String EMAIL = "email";
223237

238+
/** The Constant FILE. */
239+
public static final String FILE = "file";
240+
241+
/** The Constant HIDDEN. */
242+
public static final String HIDDEN = "hidden";
243+
224244
/** The Constant I. */
225245
public static final String I = "I";
226246

227247
/** The Constant i. */
228248
public static final String i = "i";
229249

250+
/** The Constant IMAGE. */
251+
public static final String IMAGE = "image";
252+
230253
/** The Constant LEFT. */
231254
public static final String LEFT = "left";
232255

@@ -236,31 +259,61 @@ private AttributeConstants() {
236259
/** The Constant MIDDLE. */
237260
public static final String MIDDLE = "middle";
238261

262+
/** The Constant MONTH. */
263+
public static final String MONTH = "month";
264+
239265
/** The Constant PASSWORD. */
240266
public static final String PASSWORD = "password";
241267

268+
/** The Constant PLACEHOLDER. */
269+
public static final String PLACEHOLDER = "placeholder";
270+
242271
/** The Constant RADIO. */
243272
public static final String RADIO = "radio";
244273

274+
/** The Constant RANGE. */
275+
public static final String RANGE = "range";
276+
277+
/** The Constant RESET. */
278+
public static final String RESET = "reset";
279+
245280
/** The Constant RIGHT. */
246281
public static final String RIGHT = "right";
247282

248283
/** The Constant RTL. */
249284
public static final String RTL = "rtl";
250285

286+
/** The Constant SEARCH. */
287+
public static final String SEARCH = "search";
288+
289+
/**The Constant START*/
290+
public static final String START = "start";
291+
251292
/** The Constant SUBMIT. */
252293
public static final String SUBMIT = "submit";
253294

295+
/** The Constant TEL. */
296+
public static final String TEL = "tel";
297+
254298
/** The Constant TEXT. */
255299
public static final String TEXT = "text";
256300

301+
/** The Constant TIME. */
302+
public static final String TIME = "time";
303+
257304
/** The Constant TOP. */
258305
public static final String TOP = "top";
259306

260-
/**The Constant start*/
261-
public static final String START = "start";
307+
/**The Constant URL*/
308+
public static final String URL = "url";
262309

263-
public static final String PLACEHOLDER = "placeholder";
310+
/**The Constant WEEK*/
311+
public static final String WEEK = "week";
312+
313+
/** The Constant INPUT_TYPE_VALUES. */
314+
public static final Set<String> INPUT_TYPE_VALUES = Collections.unmodifiableSet(new HashSet<>(
315+
Arrays.asList(new String[] {BUTTON, CHECKBOX, COLOR, DATE, DATETIME, DATETIME_LOCAL, EMAIL, FILE, HIDDEN,
316+
IMAGE, MONTH, NUMBER, PASSWORD, RADIO, RANGE, RESET, SEARCH, SUBMIT, TEL, TEXT, TIME, URL, WEEK})));
264317

265318
// iText custom attributes
266319
public static final class ObjectTypes{

src/test/java/com/itextpdf/html2pdf/element/InputTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,12 @@ public void buttonWithDisplayBlockTest() throws IOException, InterruptedExceptio
175175
runTest("buttonWithDisplayBlock");
176176
}
177177

178+
@Test
179+
@LogMessages(messages = @LogMessage(messageTemplate = LogMessageConstant.INPUT_TYPE_IS_INVALID))
180+
public void inputDefaultTest01() throws IOException, InterruptedException {
181+
runTest("inputDefaultTest01");
182+
}
183+
178184
@Test
179185
public void placeholderTest01() throws IOException, InterruptedException {
180186
runTest("placeholderTest01");
Binary file not shown.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
The chechbox type is set incorrectly. Thus the default type (text) should be used.
2+
<input type=\"checkbox\" id=\"check\" unchecked disabled>

0 commit comments

Comments
 (0)