gren-lang / gren-lang/core

`String.words` of a string with no words in it returns a 1-member Array instead of an empty Array

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

Nobody has claimed this yet.

bug
Dominant language
JavaScript
Stars
48
Forks
14
Avg merge
4h 14m
Merged PRs (30d)
1

Description

Found against: gren 0.6.6, gren-lang/core 7.4.2, node 22

Summary

String.words's docs say this:

Break a string into words, splitting on chunks of whitespace.

When the string it parses has 2 words, the resulting Array has 2 items.
When the string has 1 word, it returns an Array of 1 item, regardless of whitespace before or after.

Array.length (String.words "a b")   -- 2
Array.length (String.words " a ")   -- 1, the padding dropped

However when the input has no words, the result is not an empty Array.
Instead it is an Array of one empty string.

Array.length (String.words "")      -- 1
Array.first  (String.words "")      -- Just ""

The reason I believe this is a defect rather than a choice is that words never returns
empty strings anywhere else. " a " does not answer [ "", "a", "" ]; a run of
whitespace between two words does not return empty strings between them.

Every caller can therefore assume that a word is a non-empty string.

Looking at it another way, it's odd that the length of words "a" is the same length of words ""

> String.words "a b c"
["a", "b", "c"] : Array String

> String.words "a b"
["a", "b"] : Array String

> String.words "a"
["a"] : Array String

> String.words ""
[""] : Array String

Contributor guide

Open the contributing guide

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 at the String.words entry point and compare its behavior for empty, whitespace-only, one-word, and multi-word strings. Add coverage showing that an input with no words produces an empty Array, and confirm the existing examples with one or more words remain unchanged.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
developer-experience
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
72/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.