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

doesn't work when specific Japanese characters exist in a tag #250

Open
wataradio opened this issue Aug 25, 2023 · 4 comments · May be fixed by #249
Open

doesn't work when specific Japanese characters exist in a tag #250

wataradio opened this issue Aug 25, 2023 · 4 comments · May be fixed by #249
Labels

Comments

@wataradio
Copy link

wataradio commented Aug 25, 2023

Tag plugin doesn't work when specific Japanese characters, e.g '一'(U+4E00), exist in a tag like as follows.

{{tag> 一}}

Because '一's UTF-8 byte sequence(\xE4\xB8\x80) get corrupted by the following code in syntax_plugin_tag_tag::handle(tag.php).

$tags = trim($tags, "\xe2\x80\x8b"); // strip word/wordpad breaklines(U+200b)

It removes \x80 from \xE4\xB8\x80('一's UTF-8 byte sequence), and its result becomes an invalid sequence \xE4\xB8.

@wataradio
Copy link
Author

wataradio commented Aug 25, 2023

For example, the following characters' UTF-8 byte sequence end with \xe2, \x80 or \x8b, so the same problem occurs.

  • U+2000 (en quad): 0xE2, 0x80, 0x80
  • U+3000 (ideographic space): 0xE3, 0x80, 0x80
  • U+4E00 (一): 0xE4, 0xB8, 0x80
  • U+228B (⊋, contains as member): 0xE2, 0x8A, 0x8B
  • U+308B (る): 0xE3, 0x82, 0x8B

@Klap-in
Copy link
Member

Klap-in commented Aug 25, 2023

Thanks for the extra info, I think I do now understand the cause. The intent of the trim() was to remove the U+2000, i.e. a multibyte character of three pieces/bytes. However, because trim() it is not multibyte aware, it handles it as three separate characters.

So we should use here str_replace()? Does that work?

$tags = str_replace("\xe2\x80\x8b", '', $tags); // strip word/wordpad breaklines(U+200b)

@Klap-in Klap-in added the bug label Aug 25, 2023
@wataradio
Copy link
Author

Thanks, I think it works well.

I confirmed the following small test code worked expectedly.

<?php
$str = "\xE4\xB8\x80"; // "一"
$zero_width_space = "\xe2\x80\x8b"; // U+200b ZERO WIDTH SPACE
$tags = $zero_width_space . $str . $zero_width_space;

$tags = str_replace("\xe2\x80\x8b", '', $tags); 

// expecting \xe4\xb8\x80 would be printed
$bytes = unpack('C*', $tags);
foreach ($bytes as $byte) {
    echo '\\x' . dechex($byte);
}
?>

@Klap-in
Copy link
Member

Klap-in commented Aug 25, 2023

Thanks for testing. trim() works only on the end of the string, str_replace() everywhere. I think that is fine for tags. I will implement it.

@Klap-in Klap-in linked a pull request Oct 17, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants