From faa5bc2bd8849276a15728d54f6984877d659cc7 Mon Sep 17 00:00:00 2001 From: Peter Palaga Date: Fri, 22 May 2020 22:19:38 +0200 Subject: [PATCH] Remove section, key and value length limits Prepare for https://github.com/editorconfig/editorconfig-core-test/pull/41 --- .github/workflows/verify.yaml | 2 + .../main/java/org/ec4j/core/model/Glob.java | 43 ++++++++----------- .../java/org/ec4j/core/model/Property.java | 15 +------ .../org/ec4j/core/EditorConfigParserTest.java | 6 ++- 4 files changed, 24 insertions(+), 42 deletions(-) diff --git a/.github/workflows/verify.yaml b/.github/workflows/verify.yaml index 919dc3f..76c1977 100644 --- a/.github/workflows/verify.yaml +++ b/.github/workflows/verify.yaml @@ -23,6 +23,7 @@ jobs: linux: runs-on: ubuntu-18.04 strategy: + fail-fast: false matrix: java: [ 8, 11, 14 ] steps: @@ -41,6 +42,7 @@ jobs: windows: runs-on: windows-2019 strategy: + fail-fast: false matrix: java: [ 8, 11, 14 ] steps: diff --git a/core/src/main/java/org/ec4j/core/model/Glob.java b/core/src/main/java/org/ec4j/core/model/Glob.java index 0e7c091..9175208 100644 --- a/core/src/main/java/org/ec4j/core/model/Glob.java +++ b/core/src/main/java/org/ec4j/core/model/Glob.java @@ -47,7 +47,6 @@ */ public class Glob { - private static final int MAX_GLOB_LENGTH = 4096; private final PatternSyntaxException error; private final List ranges; private final Pattern regex; @@ -58,32 +57,24 @@ public class Glob { public Glob(String source) { this.source = source; this.ranges = new ArrayList(); - if (source.length() > MAX_GLOB_LENGTH) { - this.regex = null; - this.error = new PatternSyntaxException( - "Glob length exceeds the maximal allowed length of " + MAX_GLOB_LENGTH + " characters", source, - MAX_GLOB_LENGTH); - this.matchLastSegmentOnly = false; - } else { - source = ESCAPED_COMMENT_SIGNS.matcher(source).replaceAll("$1"); - final int slashPos = source.indexOf('/'); - final int doubleAsteriskPos = source.indexOf("**"); - if (slashPos >= 0) { - source = (slashPos == 0 ? source.substring(1) : source); - } - this.matchLastSegmentOnly = slashPos < 0 && doubleAsteriskPos < 0; - final StringBuilder regex = new StringBuilder(source.length()); - convertGlobToRegEx(source, ranges, regex); - PatternSyntaxException err = null; - Pattern pat = null; - try { - pat = Pattern.compile(regex.toString()); - } catch (PatternSyntaxException e) { - err = e; - } - this.error = err; - this.regex = pat; + source = ESCAPED_COMMENT_SIGNS.matcher(source).replaceAll("$1"); + final int slashPos = source.indexOf('/'); + final int doubleAsteriskPos = source.indexOf("**"); + if (slashPos >= 0) { + source = (slashPos == 0 ? source.substring(1) : source); + } + this.matchLastSegmentOnly = slashPos < 0 && doubleAsteriskPos < 0; + final StringBuilder regex = new StringBuilder(source.length()); + convertGlobToRegEx(source, ranges, regex); + PatternSyntaxException err = null; + Pattern pat = null; + try { + pat = Pattern.compile(regex.toString()); + } catch (PatternSyntaxException e) { + err = e; } + this.error = err; + this.regex = pat; } @Override diff --git a/core/src/main/java/org/ec4j/core/model/Property.java b/core/src/main/java/org/ec4j/core/model/Property.java index ba95f67..8410ac6 100644 --- a/core/src/main/java/org/ec4j/core/model/Property.java +++ b/core/src/main/java/org/ec4j/core/model/Property.java @@ -50,16 +50,6 @@ public Property build() { return new Property(sealAdapters(), type, name, value); } - boolean checkMax() { - if (name != null && name.length() > 50) { - return false; - } - if (value != null && value.getSource().length() > 255) { - return false; - } - return true; - } - /** * Adds this {@link Builder} to the parent {@link Section.Builder} using parent * {@link Section.Builder#property(Property.Builder)} and returns the parent {@link Section.Builder} @@ -67,10 +57,7 @@ boolean checkMax() { * @return the parent {@link Section.Builder} */ public Section.Builder closeProperty() { - if (checkMax()) { - parentBuilder.property(this); - } - return parentBuilder; + return parentBuilder.property(this); } /** diff --git a/core/src/test/java/org/ec4j/core/EditorConfigParserTest.java b/core/src/test/java/org/ec4j/core/EditorConfigParserTest.java index c0f1177..c6c8ccb 100644 --- a/core/src/test/java/org/ec4j/core/EditorConfigParserTest.java +++ b/core/src/test/java/org/ec4j/core/EditorConfigParserTest.java @@ -246,7 +246,7 @@ public void max_section_name_ok() throws IOException { } @Test - public void max_section_name_ignore() throws IOException { + public void max_section_name_long() throws IOException { final String testFile = "root/test4"; StringResourceTree tree = StringResourceTree.builder() // .resource("root/.editorconfig", getClass().getResource("/parser/.editorconfig"), StandardCharsets.UTF_8)// @@ -255,7 +255,9 @@ public void max_section_name_ignore() throws IOException { Collection properties = ResourcePropertiesService.default_() .queryProperties(tree.getResource(testFile)).getProperties().values(); - Assert.assertEquals(0, properties.size()); + Assert.assertEquals(1, properties.size()); + Iterator it = properties.iterator(); + Assert.assertEquals("key4 = value4", it.next().toString()); } @Test