Skip to content

Commit

Permalink
PropertyName do not match star with empty (#1147)
Browse files Browse the repository at this point in the history
  • Loading branch information
radcortez authored Apr 19, 2024
1 parent d73f24f commit bd40d1a
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 41 deletions.
25 changes: 23 additions & 2 deletions implementation/src/main/java/io/smallrye/config/PropertyName.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ public PropertyName(final String name) {
this.name = name;
}

public String getName() {
return name;
}

@Override
public boolean equals(final Object o) {
if (this == o) {
Expand All @@ -28,6 +32,10 @@ static boolean equals(final String name, final String other) {
return true;
}

if (name.equals("*") && (other.equals("") || other.equals("\"\""))) {
return false;
}

char n;
char o;

Expand All @@ -45,8 +53,12 @@ static boolean equals(final String name, final String other) {
return false;
} else if (o == '"') {
int beginQuote = other.lastIndexOf('"', i - 1);
if (beginQuote != -1 && beginQuote != 0 && other.charAt(beginQuote - 1) == '.') {
i = beginQuote;
if (beginQuote != -1) {
if (beginQuote != 0 && other.charAt(beginQuote - 1) == '.') {
i = beginQuote;
} else {
i = beginQuote;
}
}
} else {
int previousDot = other.lastIndexOf('.', i);
Expand Down Expand Up @@ -105,4 +117,13 @@ public int hashCode() {
}
return h;
}

@Override
public String toString() {
return name;
}

public static PropertyName name(final String name) {
return new PropertyName(name);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.smallrye.config;

import static io.smallrye.config.PropertyName.name;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;

Expand All @@ -8,45 +9,52 @@
class PropertyNameTest {
@Test
void mappingNameEquals() {
assertEquals(new PropertyName(new String("foo")), new PropertyName(new String("foo")));
assertEquals(new PropertyName(new String("foo.bar")), new PropertyName(new String("foo.bar")));
assertEquals(new PropertyName("foo.*"), new PropertyName("foo.bar"));
assertEquals(new PropertyName(new String("foo.*")), new PropertyName(new String("foo.*")));
assertEquals(new PropertyName("*"), new PropertyName("foo"));
assertEquals(new PropertyName("foo"), new PropertyName("*"));
assertEquals(new PropertyName("foo.*.bar"), new PropertyName("foo.bar.bar"));
assertEquals(new PropertyName("foo.bar.bar"), new PropertyName("foo.*.bar"));
assertEquals(new PropertyName("foo.*.bar"), new PropertyName("foo.\"bar\".bar"));
assertEquals(new PropertyName("foo.\"bar\".bar"), new PropertyName("foo.*.bar"));
assertEquals(new PropertyName("foo.*.bar"), new PropertyName("foo.\"bar-baz\".bar"));
assertEquals(new PropertyName("foo.\"bar-baz\".bar"), new PropertyName("foo.*.bar"));
assertNotEquals(new PropertyName("foo.*.bar"), new PropertyName("foo.bar.baz"));
assertNotEquals(new PropertyName("foo.bar.baz"), new PropertyName("foo.*.bar"));
assertEquals(new PropertyName(new String("foo.bar[*]")), new PropertyName(new String("foo.bar[*]")));
assertEquals(new PropertyName("foo.bar[*]"), new PropertyName("foo.bar[0]"));
assertEquals(new PropertyName("foo.bar[0]"), new PropertyName("foo.bar[*]"));
assertEquals(new PropertyName("foo.*[*]"), new PropertyName("foo.bar[0]"));
assertEquals(new PropertyName("foo.bar[0]"), new PropertyName("foo.*[*]"));
assertEquals(new PropertyName("foo.*[*]"), new PropertyName("foo.baz[1]"));
assertEquals(new PropertyName("foo.baz[1]"), new PropertyName("foo.*[*]"));
assertNotEquals(new PropertyName("foo.*[*]"), new PropertyName("foo.baz[x]"));
assertNotEquals(new PropertyName("foo.baz[x]"), new PropertyName("foo.*[*]"));
assertEquals(new PropertyName("foo.*[*].bar[*]"), new PropertyName("foo.baz[0].bar[0]"));
assertEquals(new PropertyName(new String("foo.*[*].bar[*]")), new PropertyName(new String("foo.*[*].bar[*]")));
assertEquals(new PropertyName("foo.baz[0].bar[0]"), new PropertyName("foo.*[*].bar[*]"));
assertEquals(new PropertyName(new String("foo.baz[0].bar[0]")), new PropertyName(new String("foo.baz[0].bar[0]")));
assertNotEquals(new PropertyName("foo.bar.baz[*]").hashCode(), new PropertyName("foo.bar.*").hashCode());
assertNotEquals(new PropertyName("foo.bar.baz[*]"), new PropertyName("foo.bar.*"));
assertEquals(name(new String("foo")), name(new String("foo")));
assertEquals(name(new String("foo.bar")), name(new String("foo.bar")));
assertEquals(name("foo.*"), name("foo.bar"));
assertEquals(name(new String("foo.*")), name(new String("foo.*")));
assertEquals(name("*"), name("foo"));
assertEquals(name("foo"), name("*"));
assertEquals(name("foo.*.bar"), name("foo.bar.bar"));
assertEquals(name("foo.bar.bar"), name("foo.*.bar"));
assertEquals(name("foo.*.bar"), name("foo.\"bar\".bar"));
assertEquals(name("foo.\"bar\".bar"), name("foo.*.bar"));
assertEquals(name("foo.*.bar"), name("foo.\"bar-baz\".bar"));
assertEquals(name("foo.\"bar-baz\".bar"), name("foo.*.bar"));
assertNotEquals(name("foo.*.bar"), name("foo.bar.baz"));
assertNotEquals(name("foo.bar.baz"), name("foo.*.bar"));
assertEquals(name(new String("foo.bar[*]")), name(new String("foo.bar[*]")));
assertEquals(name("foo.bar[*]"), name("foo.bar[0]"));
assertEquals(name("foo.bar[0]"), name("foo.bar[*]"));
assertEquals(name("foo.*[*]"), name("foo.bar[0]"));
assertEquals(name("foo.bar[0]"), name("foo.*[*]"));
assertEquals(name("foo.*[*]"), name("foo.baz[1]"));
assertEquals(name("foo.baz[1]"), name("foo.*[*]"));
assertNotEquals(name("foo.*[*]"), name("foo.baz[x]"));
assertNotEquals(name("foo.baz[x]"), name("foo.*[*]"));
assertEquals(name("foo.*[*].bar[*]"), name("foo.baz[0].bar[0]"));
assertEquals(name(new String("foo.*[*].bar[*]")), name(new String("foo.*[*].bar[*]")));
assertEquals(name("foo.baz[0].bar[0]"), name("foo.*[*].bar[*]"));
assertEquals(name(new String("foo.baz[0].bar[0]")), name(new String("foo.baz[0].bar[0]")));
assertNotEquals(name("foo.bar.baz[*]").hashCode(), name("foo.bar.*").hashCode());
assertNotEquals(name("foo.bar.baz[*]"), name("foo.bar.*"));

assertEquals(new PropertyName("foo").hashCode(), new PropertyName("foo").hashCode());
assertEquals(new PropertyName("foo.bar").hashCode(), new PropertyName("foo.bar").hashCode());
assertEquals(new PropertyName("foo.*").hashCode(), new PropertyName("foo.bar").hashCode());
assertEquals(new PropertyName("foo.*.bar").hashCode(), new PropertyName("foo.bar.bar").hashCode());
assertEquals(new PropertyName("foo.*.bar").hashCode(), new PropertyName("foo.\"bar\".bar").hashCode());
assertEquals(new PropertyName(new String("foo.\"bar\".bar")).hashCode(),
new PropertyName(new String("foo.\"bar\".bar")).hashCode());
assertEquals(new PropertyName("foo.*.bar").hashCode(), new PropertyName("foo.\"bar-baz\".bar").hashCode());
assertEquals(new PropertyName(new String("foo.\"bar-baz\".bar")).hashCode(),
new PropertyName(new String("foo.\"bar-baz\".bar")).hashCode());
assertEquals(name("foo").hashCode(), name("foo").hashCode());
assertEquals(name("foo.bar").hashCode(), name("foo.bar").hashCode());
assertEquals(name("foo.*").hashCode(), name("foo.bar").hashCode());
assertEquals(name("foo.*.bar").hashCode(), name("foo.bar.bar").hashCode());
assertEquals(name("foo.*.bar").hashCode(), name("foo.\"bar\".bar").hashCode());
assertEquals(name(new String("foo.\"bar\".bar")).hashCode(), name(new String("foo.\"bar\".bar")).hashCode());
assertEquals(name("foo.*.bar").hashCode(), name("foo.\"bar-baz\".bar").hashCode());
assertEquals(name(new String("foo.\"bar-baz\".bar")).hashCode(), name(new String("foo.\"bar-baz\".bar")).hashCode());

assertEquals(name("*"), name("\"foo\""));
assertEquals(name("\"foo\""), name("*"));

assertEquals(name("*.bar"), name("foo.bar"));
assertEquals(name("*.bar"), name("\"foo\".bar"));

assertNotEquals(name("*"), name(""));
assertNotEquals(name(""), name("*"));
}
}

0 comments on commit bd40d1a

Please sign in to comment.