craftcms / craftcms/cms

Snake Filter - punctuation such as slashes and colons do not get replaced

Open
#7,173 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
PHP
Stars
3.6k
Forks
705
Avg merge
1d 5h
Merged PRs (30d)
134

Description

Description

When using the snake filter in Craft 3, some of the punctuation such as dots, slashes and colons do not get replaced with underscores. Is there a known solution to solve this when moving code from C2 to C3.

If I output the following twig template code for example.

{% set example = "https://example.com/hello-world-dash" %}
{{ example|snake }}
{{ "https://another-example.com/hello-world-dash"|snake }}

It will display like below

https://example.com/hello_world_dash 
https://another_example.com/hello_world_dash

Instead of

https_example_com_hello_world_dash 
https_another_example_com_hello_world_dash

A similar ticket can be found here but no responses - https://github.com/craftcms/cms/issues/5870

Steps to reproduce
  1. Use a URL and apply Snake filter
  2. Output will show slashes and colons etc
Additional info
  • Craft version: 3.5.8
  • PHP version: 7.4.X
  • Database driver & version:
  • Plugins & versions:

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 by reproducing the issue in a Twig template with the documented URL examples and the snake filter on Craft 3.5.8. Trace the snake filter's punctuation handling and compare it with the expected underscore output; done means dots, slashes, and colons are replaced while existing hyphen handling remains correct.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.