Skip to content

Commit

Permalink
Remove section, key and value length limits
Browse files Browse the repository at this point in the history
  • Loading branch information
ppalaga committed Jul 27, 2020
1 parent 9976b42 commit c318f00
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 42 deletions.
43 changes: 17 additions & 26 deletions core/src/main/java/org/ec4j/core/model/Glob.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
*/
public class Glob {

private static final int MAX_GLOB_LENGTH = 4096;
private final PatternSyntaxException error;
private final List<int[]> ranges;
private final Pattern regex;
Expand All @@ -58,32 +57,24 @@ public class Glob {
public Glob(String source) {
this.source = source;
this.ranges = new ArrayList<int[]>();
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
Expand Down
15 changes: 1 addition & 14 deletions core/src/main/java/org/ec4j/core/model/Property.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,27 +50,14 @@ 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}
*
* @return the parent {@link Section.Builder}
*/
public Section.Builder closeProperty() {
if (checkMax()) {
parentBuilder.property(this);
}
return parentBuilder;
return parentBuilder.property(this);
}

/**
Expand Down
6 changes: 4 additions & 2 deletions core/src/test/java/org/ec4j/core/EditorConfigParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)//
Expand All @@ -255,7 +255,9 @@ public void max_section_name_ignore() throws IOException {

Collection<Property> properties = ResourcePropertiesService.default_()
.queryProperties(tree.getResource(testFile)).getProperties().values();
Assert.assertEquals(0, properties.size());
Assert.assertEquals(1, properties.size());
Iterator<Property> it = properties.iterator();
Assert.assertEquals("key4 = value4", it.next().toString());
}

@Test
Expand Down

0 comments on commit c318f00

Please sign in to comment.