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.
Options

how do i make @ to work with Chinese username

jeongweejeongwee Vanilla version 2.6 ✭✭

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

  • Options
    jeongweejeongwee Vanilla version 2.6 ✭✭

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

  • Options
    jeongweejeongwee Vanilla version 2.6 ✭✭

    add this right?

    image

    but my lines looks diffrent

    image

    im 2.1b1

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

  • Options
    R_JR_J Ex-Fanboy Munich Admin
    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
  • Options
    jeongweejeongwee Vanilla version 2.6 ✭✭

    @R_J is it here?image

  • Options
    R_JR_J Ex-Fanboy Munich Admin

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

  • Options
    jeongweejeongwee Vanilla version 2.6 ✭✭

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

  • Options
    R_JR_J Ex-Fanboy Munich Admin

    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}

  • Options
    jeongweejeongwee Vanilla version 2.6 ✭✭

    @R_J
    my file doesnt have line

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

    its 2.1b1 here.

  • Options
    R_JR_J Ex-Fanboy Munich Admin

    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
                );
             }
    
  • Options
    jeongweejeongwee Vanilla version 2.6 ✭✭

    @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.

  • Options
    R_JR_J Ex-Fanboy Munich Admin

    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

  • Options
    jeongweejeongwee Vanilla version 2.6 ✭✭
    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 :(
  • Options
    R_JR_J Ex-Fanboy Munich Admin

    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...

  • Options
    vrijvlindervrijvlinder Papillon-Sauvage MVP
    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

  • Options
    ShadowdareShadowdare r_j MVP
    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

  • Options
    R_JR_J Ex-Fanboy Munich Admin

    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!

  • Options
    R_JR_J Ex-Fanboy Munich Admin

    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}"));
    
  • Options
    jeongweejeongwee Vanilla version 2.6 ✭✭

    @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.

  • Options
    R_JR_J Ex-Fanboy Munich Admin

    @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.