Skip to content

Allow start/end checks on empty strings #1135

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 2, 2020

Conversation

jvrsantacruz
Copy link
Contributor

When using this library function on strings that come from a parameter,
they might be empty sometimes, rendering it difficult to use, having to
force hacks like.

"_${source}".stdlib::start_with('_puppet:///modules/')

Where _ is added to make sure that the string is never empty.

In Ruby the start_with? function allows being used on empty strings,
and it returns false for any assertion to be done:

p ''.start_with?('test')
false

Also in Python the startswith() method returns false for empty
strings:

In [1]: print(''.startswith('test'))
False

As this logic seems the most extended and allows for a wider use of the
library, removing these corner cases when the string is empty seems like a good idea.

When using this library function on strings that come from a parameter,
they might be empty sometimes, rendering it difficult to use, having to
force hacks like.

    "_${source}".stdlib::start_with('_puppet:///modules/')

Where `_` is added to make sure that the string is never empty.

In Ruby the `start_with?` function allows being used on empty strings,
and it returns `false` for any assertion to be done:

    p ''.start_with?('test')
    false

Also in Python the `startswith()` method returns `false` for empty
strings:

    In [1]: print(''.startswith('test'))
    False

As this logic seems the most extended and allows for a wider use of the
library, removing corner cases when the string comes empty.
@jvrsantacruz jvrsantacruz requested a review from a team as a code owner October 22, 2020 12:15
@puppet-community-rangefinder
Copy link

stdlib::end_with is a function

that may have no external impact to Forge modules.

stdlib::start_with is a function

that may have no external impact to Forge modules.

This module is declared in 319 of 575 indexed public Puppetfiles.


These results were generated with Rangefinder, a tool that helps predict the downstream impact of breaking changes to elements used in Puppet modules. You can run this on the command line to get a full report.

Exact matches are those that we can positively identify via namespace and the declaring modules' metadata. Non-namespaced items, such as Puppet 3.x functions, will always be reported as near matches only.

@DavidS DavidS self-assigned this Nov 2, 2020
@DavidS DavidS added the feature label Nov 2, 2020
@DavidS DavidS merged commit 2fafe78 into puppetlabs:main Nov 2, 2020
@DavidS
Copy link
Contributor

DavidS commented Nov 2, 2020

Thanks for your contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants