Skip to content
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

Slugify handle empty strings #912

Merged
merged 5 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion integration_tests/tests/jinja_helpers/test_slugify.sql
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
with comparisons as (
select '{{ dbt_utils.slugify("") }}' as output, '' as expected
union all
select '{{ dbt_utils.slugify(None) }}' as output, '' as expected
union all
select '{{ dbt_utils.slugify("!Hell0 world-hi") }}' as output, 'hell0_world_hi' as expected
union all
select '{{ dbt_utils.slugify("0Hell0 world-hi") }}' as output, '_0hell0_world_hi' as expected
)

select *
from comparisons
where output != expected
where output != expected
6 changes: 5 additions & 1 deletion macros/jinja_helpers/slugify.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{% macro slugify(string) %}

{% if not string %}
{{ return('') }}
{% endif %}

{#- Lower case the string -#}
{% set string = string | lower %}
{#- Replace spaces and dashes with underscores -#}
Expand All @@ -11,4 +15,4 @@

{{ return(string) }}

{% endmacro %}
{% endmacro %}