isXander / isXander/YetAnotherConfigLib

Inputting text when using an `IStringController` with input validation is overly restrictive

Open
#195 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
155
Forks
68
PR merge metrics
No merged PRs in 30d

Description

When using an implementation of IStringController where input validation is used, the user is unable to enter an invalid value.

This is an issue for certain kinds of input validation, for example:

  • validating if the input is a valid element of a registry
  • validating if the input can be properly parsed
  • etc.

Here is a concrete example:

class ModifierExpressionController(
    private val option: Option<BeaconModifierExpression>,
) : IStringController<BeaconModifierExpression> {
    override fun isInputValid(input: String): Boolean {
        return try {
            val expression = BeaconModifierExpression(input)
            expression.evaluate(0.0) // try evaluating it to make sure it gets parsed (we parse it lazily)
            true
        } catch (e: ParseException) {
            false
        }
    }

    override fun option() = option

    override fun getString() = option.pendingValue().expressionString

    override fun setFromString(value: String) {
        option.requestSet(BeaconModifierExpression(value))
    }
}

The input is expected to be an equation which can use various functions such as min, cos, log, etc., as well as standard math operations such as +, -, *, etc.
The issue is, if you wanted to input an expression such as 1 + 1. you will begin typing the expression by doing 1. This is a valid expression. But then you'll attempt to input + resulting in 1+. This is not a valid expression. However, the invalid expression is an intermediary step on the way to a valid one, as next 1 will be typed, resulting in 1+1.

The same thing might happen if you're, for example, required to input a valid registry entry, such as a valid mob id.
the mob id m is not a valid mob id, however it is required when attempting to type out the full id of minecraft:creeper.

I think a better alternative rather than not allowing the character to be typed would be to simply make the box red and make it the config unable to be saved, indicating that the input is invalid.

Contributor guide

No contributing guide indexed for this repository

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.

Research direction

Start by tracing IStringController input validation through the text-editing flow and how invalid intermediate values are handled. Verify that users can enter temporarily invalid strings such as 1+ or m, while the input is visibly marked invalid and the configuration cannot be saved until validation succeeds.

Written by the indexing model from the issue text.

Assessment

Tech stack
kotlin
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.