Skip to content

[String] AsciiSlugger : iconv(): Wrong charset, conversion from UTF-8' to ASCII//IGNORE//TRANSLIT' is not allowed #37213

@gnutix

Description

@gnutix

Symfony version(s) affected: 5.0.7

Description
Passing extended UTF-8 characters into AsciSlugger->slug() throws an error :

iconv(): Wrong charset, conversion from `UTF-8' to `ASCII//IGNORE//TRANSLIT' is not allowed

Stacktrace: image

How to reproduce

<?php
use Symfony\Component\String\Slugger\AsciiSlugger;

(new AsciiSlugger())->slug('😋');

I tried with an emoji 😋 and a braille character , but probably that other characters have the same fate.

Possible Solutions

  1. Remove the characters that would trigger this error (preemptively or by catching it)
  2. Delegate the decision to the user by providing a callable to the slug method that would receive the "faulty" character as input :
use Symfony\Component\String\Slugger\AsciiSlugger;

$slug = (new AsciiSlugger())->slug('😋', '-', null, fn(string $c) => '');

var_dump($slug->toString()); // outputs ""

Additional context
Here's a list of characters to play with : https://www.utf8-chartable.de/unicode-utf8-table.pl

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions