Sentence generator code sometimes returns an empty string

Created on 13 November 2020, over 3 years ago
Updated 4 May 2023, about 1 year ago

Problem/Motivation

The Generator has a bug where certain sentences will be randomly empty.

The buggy line is this:
https://git.drupalcode.org/project/styleguide/-/blob/13260024/src/Genera...

The bug occurs because the string generated by Drupal's lorem ipsom generator always has a trailing full-stop.
Which means that when the $explode = explode('.', $graph); code is called, the last array entry is always an empty string, and whenever the $rand = array_rand($explode); returns the last index. The output is always an empty string with a full stop at the end.

Steps to reproduce

It's random. But should be evident refreshing a couple times and reviewing the sentences.

Proposed resolution

Filter out empty strings from the array, or trim full-stops from the initial $graph before exploding.

Remaining tasks

User interface changes

N/A

API changes

N/A

Data model changes

N/A

πŸ› Bug report
Status

Closed: duplicate

Version

2.0

Component

Code

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024