Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

how do i make @ to work with Chinese username

this is the link http://15min.cc/index.php?p=/discussion/43/test-user#latest

can anyone take a look and help me

Best Answer

«1

Answers

  • @R_J
    =.= sry ,my english sucks..... where shud i click ...and where shud i put the file.image

  • add this right?

    image

    but my lines looks diffrent

    image

    im 2.1b1

    how do i do now..................

    1. Open the link
    2. Click at "Files Changed"
    3. Find the name of the file to change
    4. Open it in your forum
    5. Comment out what is marked read
    6. Add what is marked green
    7. Try if it works for you
  • @R_J is it here?image

  • exchange '/(?:^|[\s,\.>])@(\w{3,20})\b/i', by '/(?:^|[\s,\.>])@('.ValidateUsernameRegex().')\b/i', in library/core/functions.general.php

  • @R_J still same , not working with @ Chinese words..................

  • According to that: https://github.com/vanillaforums/Garden/pull/1653/files
    change in file library/core/class.format.php '/(^|[\s,\.>])@(\w{1,50})\b/i', //{3,20} with '/(^|[\s,\.>])@('.ValidateUsernameRegex().')\b/i', //{3,20}

  • @R_J
    my file doesnt have line

      '/(^|[\s,\.>])@(\w{1,50})\b/i', //{3,20}
    

    its 2.1b1 here.

  • Search for that in library/core/class.format.php:

     // Handle @mentions.
             if(C('Garden.Format.Mentions')) {
                $Mixed = preg_replace(
                   '/(^|[\s,\.>])@(\w{1,50})\b/i', //{3,20}
                   '\1'.Anchor('@\2', '/profile/\\2'),
                   $Mixed
                );
             }
    
  • @R_J i changed my library/core/functions.general.php file back. shud i change both? if only change

     // Handle @mentions.
             if(C('Garden.Format.Mentions')) {
                $Mixed = preg_replace(
                   '/(^|[\s,\.>])@(\w{1,50})\b/i', //{3,20}
                   '\1'.Anchor('@\2', '/profile/\\2'),
                   $Mixed
                );
             }

    i have done change it,and it still not working with chinese words.

  • You have to change both files. Try to understand what you are doing ;-)

    • the file you are looking at has a regular expression that searches for @username, but username is not allowed to contain chinese symbols.
    • When you change it to '/(^|[\s,\.>])@('.ValidateUsernameRegex().')\b/i', it uses the function ValidateUsernameRegex.
    • You can find the function here : https://github.com/vanillaforums/Garden/search?q=ValidateUsernameRegex&ref=cmdform
    • there you can see that it compares usernames to C("Garden.User.ValidationRegex")
    • so you have to make a config setting $Configuration['Garden']['User']['ValidationRegex'] = '\d\w_';
    • now google for a regex that allows all chinese symbols and add that to the above config file.

    The changes to the 1. functions.general.php 2. class.format.php and 3. config.ini should be enaugh to solve your problem

  • jeongweejeongwee ✭✭
    edited August 2013

    i have done 1-5 steps alrdy.

    1.the file you are looking at has a regular expression that searches for @username, but username is not allowed to contain chinese symbols.

    2.When you change it to

     '/(^|[\s,\.>])@('.ValidateUsernameRegex().')\b/i'
    , it uses the function ValidateUsernameRegex.

    3.You can find the function here : https://github.com/vanillaforums/Garden/search?q=ValidateUsernameRegex&ref=cmdform

    4.there you can see that it compares usernames to C("Garden.User.ValidationRegex")

    5.so you have to make a config setting $Configuration['Garden']['User']['ValidationRegex'] = '\d\w_';

    im sure i did right by follow the steps,and it still havnt solved the problem.

    so the "6.now google for a regex that allows all chinese symbols and add that to the above config file."is my last hope:(

    what keyword shud i search? "regex chinese symbols?"i don really know wat shud i do ...i have searched it and nothing is looks like

    $Configuration['Garden']['User'] 
    im confused :(
  • I do not know how chinese symbols are called. There must be a chinese word for it. Look for that word and "regex". I'll try for myself but your chances are bigger than mine, I'd bet...

  • edited August 2013

    so the "6.now google for a regex that allows all chinese symbols and add that to the above config file."is my last hope:(

    that is the most important one because that is what the regex will check against. I recommend unicode

    try using this in the config values for the regex

    $Configuration['Garden']['User']['ValidationRegex'] = '/^([\p{L}\p{N}\p{Pd}\p{Pc}\p{Lm}\p{M}]{3,20}+)?$/';

    regex= regular expressions

    http://www.regular-expressions.info/unicode.html

  • edited August 2013

    If the string is encoded in UTF-8, this regex will probably match all Chinese characters:

    $Configuration['Garden']['User']['ValidationRegex'] = '/[^\x{4E00}-\x{9FA5}]/u';

    Add Pages to Vanilla with the Basic Pages app

  • Seems to be complicated: chinese symbols are unicode characters and they require a special switch, but you can not set that in config.

    That is the regex you need in your config: ' [\x{4E00}-\x{9FA5}]\d\w_' (at least that's what google told me

    But you also have to go to the lines that you've already changed in functions.general.php and class.format.php and change /i'(end of the line) to '/iu'

    I'm no expert with regular expressions. Try to sign in with a chinese user name after you've made the changes!

  • I'm third - I should have updated the thread before posting...

    Wouldn't the switch be a problem?

    if (!function_exists('ValidateUsernameRegex')) {
       function ValidateUsernameRegex() {
          static $ValidateUsernameRegex;
    
          if (is_null($ValidateUsernameRegex)) {
             $ValidateUsernameRegex = sprintf("[%s]%s",
                C("Garden.User.ValidationRegex","\d\w_"),
                C("Garden.User.ValidationLength","{3,20}"));
    
  • @vrijvlinder @Shadowdare
    the codes

    $Configuration['Garden']['User']['ValidationRegex'] = '/^([\p{L}\p{N}\p{Pd}\p{Pc}\p{Lm}\p{M}]{3,20}+)?$/';

    and

    $Configuration['Garden']['User']['ValidationRegex'] = '/[^\x{4E00}-\x{9FA5}]/u';

    just made the discussion and comments disappear.

  • @jeongwee said:
    vrijvlinder Shadowdare
    the codes

    $Configuration['Garden']['User']['ValidationRegex'] = '/^([\p{L}\p{N}\p{Pd}\p{Pc}\p{Lm}\p{M}]{3,20}+)?$/';

    and

    $Configuration['Garden']['User']['ValidationRegex'] = '/[^\x{4E00}-\x{9FA5}]/u';

    just made the discussion and comments disappear.

    Regex are a bitch... :-D

Sign In or Register to comment.