jqwik icon indicating copy to clipboard operation
jqwik copied to clipboard

@NotBlank can generate blank strings containing UTF-8 whitespace characters

Open jacopocav-mollie opened this issue 7 months ago • 4 comments

The following test generates the " " string, which contains a UTF-8 whitespace character (see https://unicodeplus.com/U+1680). " ".isBlank() returns true, and Character.isWhitespace(' ') returns true.

import net.jqwik.api.ForAll;
import net.jqwik.api.Property;
import net.jqwik.api.constraints.NotBlank;

public class BlankTest {
    @Property(seed = "9077689816503037655")
    boolean shouldNotBeBlank(@ForAll @NotBlank String string) {
        return !string.isBlank();
    }
}

The problem seems to be with this method in NotBlankConfigurator:

public Arbitrary<String> configure(Arbitrary<String> arbitrary, NotBlank notBlank) {
	return arbitrary.filter(s -> s != null && !s.trim().isEmpty());
}

s.trim() does not consider UTF-8 whitespace characters. It should use strip instead:

!s.strip().isEmpty()

or just isBlank:

!s.isBlank()

jacopocav-mollie avatar Sep 10 '25 09:09 jacopocav-mollie

@jacopocav-mollie Makes absolutely sense. My goal is to make a bug fix release shortly and include a fix for that.

jlink avatar Sep 11 '25 13:09 jlink

Sorry for not addressing this. I would, but I'm currently fighting over getting Maven Central publishing working again. Sonatype have changed their basic publishing mechanism and I haven't succeeded yet in adapting jqwik's configuration to it.

jlink avatar Nov 15 '25 10:11 jlink

@jlink , I’ve good experience with https://github.com/GradleUp/nmcp. I recently moved to generate the pgp key in github actions, and store it in secrets. It enables one-click releases to Central.

See:

  • https://github.com/pgjdbc/pgjdbc/blob/master/.github/workflows/pgp-key-maintenance.yaml
  • https://github.com/pgjdbc/pgjdbc/blob/master/.github/workflows/release.yml
  • https://github.com/pgjdbc/pgjdbc/blob/master/.github/actions/update_version/action.yaml

vlsi avatar Nov 15 '25 10:11 vlsi

@jlink , I’ve good experience with https://github.com/GradleUp/nmcp. I recently moved to generate the pgp key in github actions, and store it in secrets. It enables one-click releases to Central.

Thanks, for the reference. I still hope I can remain using the old approach (Sonatype offers a bridge). I'm currently in conversation with Sonatype support about why it doesn't work.

nmcp will be the next thing I'll look at if the above fails.

I'd tend to prefer releasing from my machine - at least in the beginning. But that should also be possible with nmcp I assume.

jlink avatar Nov 15 '25 11:11 jlink