Skip to content

✨ feat: add slugify function#1357

Merged
harehare merged 1 commit intomainfrom
feat/add-slugify-function
Feb 28, 2026
Merged

✨ feat: add slugify function#1357
harehare merged 1 commit intomainfrom
feat/add-slugify-function

Conversation

@harehare
Copy link
Copy Markdown
Owner

No description provided.

Copilot AI review requested due to automatic review settings February 28, 2026 07:14
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new slugify helper to mq’s built-in module and wires it into the existing mq-level builtin test suite.

Changes:

  • Add slugify(s, separator = "-") to crates/mq-lang/builtin.mq using downcase() + gsub() normalization.
  • Add test_slugify and register it in the run_tests list in crates/mq-lang/builtin_tests.mq.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
crates/mq-lang/builtin.mq Introduces slugify function implemented via regex-based substitutions.
crates/mq-lang/builtin_tests.mq Adds/registrations mq-level tests for slugify’s default behavior.

end
end

# Converts a string into a URL-friendly slug by lowercasing, replacing non-alphanumeric characters with hyphens, and trimming hyphens from the ends.
Copy link

Copilot AI Feb 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The doc comment says the function replaces non-alphanumeric characters with hyphens, but the function signature allows a custom separator. Either document that the separator is configurable (and clarify ASCII vs Unicode behavior, since the regex is [a-z0-9]) or adjust the implementation/doc to match the intended semantics.

Suggested change
# Converts a string into a URL-friendly slug by lowercasing, replacing non-alphanumeric characters with hyphens, and trimming hyphens from the ends.
# Converts a string into a URL-friendly slug by lowercasing, replacing runs of non-ASCII-alphanumeric
# characters with the given `separator` (default "-"), and trimming leading/trailing hyphens.

Copilot uses AI. Check for mistakes.
Comment on lines +603 to +612
def test_slugify():
let result1 = slugify("Hello World!")
| assert_eq(result1, "hello-world")

| let result2 = slugify("This is a test.")
| assert_eq(result2, "this-is-a-test")

| let result3 = slugify("Special characters: @#$%^&*()")
| assert_eq(result3, "special-characters")
end
Copy link

Copilot AI Feb 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests cover the default slugify behavior, but there’s no coverage for the newly added separator parameter (and its edge cases like leading/trailing separators). Add at least one test that passes a non-"-" separator and asserts the expected trimming/collapsing behavior.

Copilot generated this review using guidance from repository custom instructions.
Comment on lines +621 to +626
# Converts a string into a URL-friendly slug by lowercasing, replacing non-alphanumeric characters with hyphens, and trimming hyphens from the ends.
def slugify(s, separator = "-"):
s
| downcase()
| gsub("[^a-z0-9]+", separator)
| gsub("^-+|-+$", "")
Copy link

Copilot AI Feb 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

slugify exposes a separator parameter, but the trimming step hard-codes hyphens (gsub("^-+|-+$", "")). If callers pass a different separator (e.g. _), leading/trailing separators won’t be removed, and the doc comment also implies hyphens regardless of the parameter. Consider either removing the separator parameter or updating the implementation to trim the chosen separator (and avoid regex-replacement surprises for characters like $ in the separator).

Suggested change
# Converts a string into a URL-friendly slug by lowercasing, replacing non-alphanumeric characters with hyphens, and trimming hyphens from the ends.
def slugify(s, separator = "-"):
s
| downcase()
| gsub("[^a-z0-9]+", separator)
| gsub("^-+|-+$", "")
# Converts a string into a URL-friendly slug by lowercasing, replacing non-alphanumeric characters with the given separator, and trimming that separator from the ends.
def slugify(s, separator = "-"):
s
| downcase()
| gsub("[^a-z0-9]+", separator)
| split(separator)
| map(select(. != ""))
| join(separator)

Copilot uses AI. Check for mistakes.
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Feb 28, 2026

Merging this PR will not alter performance

✅ 29 untouched benchmarks


Comparing feat/add-slugify-function (7a19a19) with main (f4b6efb)1

Open in CodSpeed

Footnotes

  1. No successful run was found on main (a004113) during the generation of this report, so f4b6efb was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@harehare harehare merged commit c776692 into main Feb 28, 2026
11 checks passed
@harehare harehare deleted the feat/add-slugify-function branch February 28, 2026 09:35
@harehare harehare restored the feat/add-slugify-function branch February 28, 2026 12:45
@harehare harehare deleted the feat/add-slugify-function branch March 15, 2026 14:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants