Skip to content

Commit 85f8bd4

Browse files
committed
feature: [174] Remove redundant changes
1 parent c9f4663 commit 85f8bd4

2 files changed

Lines changed: 2 additions & 77 deletions

File tree

acl-mug-dsl/src/main/java/javasabr/mqtt/acl/mug/dsl/parser/GaclParser.java

Lines changed: 2 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -188,13 +188,12 @@ public class GaclParser {
188188
createDirective("denySubscribe", DenySubscribeAclRule::new));
189189

190190
public List<AclRule> parse(String input) {
191-
String cleaned = stripComments(input);
192191
try {
193192
return DIRECTIVE
194193
.atLeastOnce()
195-
.parseSkipping(WHITESPACE, cleaned);
194+
.parseSkipping(WHITESPACE, input);
196195
} catch (Parser.ParseException e) {
197-
throw new AclConfigurationException("Syntax error at %s".formatted(toLineColumn(cleaned, e.getSourceIndex())));
196+
throw new AclConfigurationException("Syntax error at %s".formatted(toLineColumn(input, e.getSourceIndex())));
198197
}
199198
}
200199

@@ -217,53 +216,6 @@ private MqttUserCondition toUserCondition(String identityType, ValueMatcher<Stri
217216
};
218217
}
219218

220-
private String stripComments(String input) {
221-
StringBuilder sb = new StringBuilder(input.length());
222-
int i = 0;
223-
boolean inString = false;
224-
char stringDelimiter = '\0';
225-
while (i < input.length()) {
226-
char c = input.charAt(i);
227-
if (inString) {
228-
sb.append(c);
229-
if (c == '\\' && i + 1 < input.length()) {
230-
i++;
231-
sb.append(input.charAt(i));
232-
} else if (c == stringDelimiter) {
233-
inString = false;
234-
}
235-
i++;
236-
} else if (c == '"' || c == '\'') {
237-
inString = true;
238-
stringDelimiter = c;
239-
sb.append(c);
240-
i++;
241-
} else if (i + 1 < input.length() && c == '/' && input.charAt(i + 1) == '/') {
242-
while (i < input.length() && input.charAt(i) != '\n') {
243-
i++;
244-
}
245-
} else if (i + 1 < input.length() && c == '/' && input.charAt(i + 1) == '*') {
246-
i += 2;
247-
boolean closed = false;
248-
while (i + 1 < input.length()) {
249-
if (input.charAt(i) == '*' && input.charAt(i + 1) == '/') {
250-
i += 2;
251-
closed = true;
252-
break;
253-
}
254-
i++;
255-
}
256-
if (!closed) {
257-
throw new AclConfigurationException("Unterminated block comment");
258-
}
259-
} else {
260-
sb.append(c);
261-
i++;
262-
}
263-
}
264-
return sb.toString();
265-
}
266-
267219
private String toLineColumn(String input, int index) {
268220
int line = 1;
269221
int col = 1;

acl-mug-dsl/src/test/groovy/javasabr/mqtt/acl/mug/dsl/parser/GaclParserTest.groovy

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -309,31 +309,4 @@ class GaclParserTest extends Specification {
309309
where:
310310
pattern << ['//admin', 'a/*b']
311311
}
312-
313-
def "should report correct error position relative to original input when comments are present"() {
314-
when:
315-
GaclParser.parse("""// comment line 1
316-
// comment line 2
317-
allowPublish {
318-
users { anyUser() }
319-
topics { bad() }
320-
}""")
321-
322-
then:
323-
def e = thrown(AclConfigurationException)
324-
e.message == "Syntax error at line 5, column 12"
325-
}
326-
327-
def "should report clear error for unterminated block comment"() {
328-
when:
329-
GaclParser.parse("""allowPublish {
330-
users { anyUser() }
331-
/* this comment is never closed
332-
topics { anyTopic() }
333-
}""")
334-
335-
then:
336-
def e = thrown(AclConfigurationException)
337-
e.message.toLowerCase().contains("unterminated") || e.message.toLowerCase().contains("unclosed")
338-
}
339312
}

0 commit comments

Comments
 (0)