Verbs.java silently drops SET with an empty argument

Open Beginner friendly
#442 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
82/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
java
Domain
tooling

Research direction

Start at src/main/java/org/xembly/Verbs.java lines 182-185, where part.split(String.valueOf(quote), 0) drops trailing empty fields so SET '' yields a single token and simpleCommand() returns an empty optional; changing the limit to -1 should route the empty argument into the existing three-field branch. Read the surrounding parse loop and directives() to confirm the buffered command is then consumed. Add regression tests in the parsing test class covering both quote styles and overwriting existing text, and check the round trip new Directives(new Directives().set("").toString()). Done means the example in the issue returns an empty text content and mvn test passes.

Written by the indexing model from the issue text.

Description

SET '' is silently discarded when parsed from a script, so clearing an element leaves its previous text intact. For example:

Document dom = new Xembler(
    new Directives("ADD 'root'; SET 'keep'; SET '';")
).dom();
// Expected: dom.getDocumentElement().getTextContent().equals("")
// Actual:   dom.getDocumentElement().getTextContent().equals("keep")

In src/main/java/org/xembly/Verbs.java:182–185, splitting with limit zero removes trailing empty strings:

final String[] args = part.split(String.valueOf(quote), 0);
final Optional<Callback<Directive>> cmd;
if (args.length == 1) {
    cmd = Optional.empty();

For SET '', this leaves only the command prefix. simpleCommand() returns an empty optional, and directives() finishes with the buffered command unconsumed. This also breaks the round trip through new Directives(new Directives().set("").toString()); the builder's valid empty value disappears during parsing.

Preserve the trailing fields in simpleCommand() so the existing three-field branch receives the empty argument:

final String[] args = part.split(String.valueOf(quote), -1);

Add regression coverage for both quote styles and for clearing text that is already present.

Dominant language
Java
Stars
248
Forks
33
Avg merge
17h 59m
Merged PRs (30d)
46

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from yegor256/xembly

All issues in yegor256/xembly

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.