Skip to content

IsSlug does not respect CustomSub #93

@odparraj

Description

@odparraj

Hi, first of all thank you for this useful package!

I've noticed that the current IsSlug function does not take into account the CustomSub defined via slug.CustomSub. This causes IsSlug to return false for strings that are technically valid slugs under custom substitution rules.

Example:

slug.CustomSub = map[string]string{
    "_": "-", // convert underscores to dashes
}

slug.IsSlug("hello-world") // true
slug.IsSlug("hello_world") // returns true, but should be false based on substitution

Suggested fix:
I propose updating IsSlug to:

func IsSlug(text string) bool {
    return text != "" && Make(text) == text
}

This way, IsSlug checks if the input is equal to what Make would return, taking into account all current configuration and substitutions.

Let me know what you think — I’d be happy to submit a PR if this change is acceptable.

Thanks again!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions