• Problem with Special Character in Snippet Parameter#

  • ddecjc Reply #1, 6 years, 1 month ago

    Reply
    I have already posted this in the Snippets forum because I thought it was a problem with the NewsListing snippet, but I've been advised that's it's a parser issue, so I'm reposting here:

    I'm trying to set up a site in Spanish, and I need to be able to put an accented character in the &truncText parameter of the NewsListing. This is what I've got right now...
    [!NewsListing? &tpl=`NewsListingTemplate` &startID=`2` &truncText=`Lea más...` &summarize=`99`!]
    

    Problem is that everything after the word "Lea" is ignored, so it is only rendered as "Lea " (including the space).

    Is there anything that I can do to fix this? Do I need to file a bug report? If I need to come up with a fix myself, can someone at least point me to the right file?

    Thanks.


  • opengeek Reply #2, 6 years, 1 month ago

    Reply
    Quote from: ddecjc at Apr 03, 2006, 04:51 PM
    Is there anything that I can do to fix this? Do I need to file a bug report? If I need to come up with a fix myself, can someone at least point me to the right file?

    Yes, please file a bug report for this and I will take a look and try and slip it in the pending release. If you're interested in looking and contributing potential solutions, feel free to take a look at /manager/includes/document.parser.class.inc.php, and start with the parseProperties() function.


  • ddecjc Reply #3, 6 years, 1 month ago

    Reply
    Bug report filed as FS#334. I listed severity as medium because it probably doesn't happen often enough to be high or critical for the general population. For me, however, it is critical. Thanks for looking at it. I will also try to take a look at the code you mentioned.


  • ddecjc Reply #4, 6 years, 1 month ago

    Reply
    I looked in document.parser.class.inc.php and found the source of the problem. It is on line 763 in the evalSnippets function.
    $tempSnippetParams = split($splitter, $tempSnippetParams);
    

    When this line is executed to split the parameters into an array, the splitter is the "&" character. Since the html representation of many special character contains an "&" (for example, the html source for á is á), an unintended split occurs which results in the parameter string for
    [!NewsListing? &tpl=`NewsListingTemplate` &startID=`2` &truncText=`Lea más...`!]
    

    being split into
    $tempSnippetParams = array(6) {
      [0]=>
      string(1) " "
      [1]=>
      string(26) "tpl=`NewsListingTemplate` "
      [2]=>
      string(12) "startID=`2` "
      [3]=>
      string(16) "truncText=`Lea m"
      [4]=>
      string(13) "aacute;s...` "
      [5]=>
      string(13) "summarize=`1`"
    }
    



  • opengeek Reply #5, 6 years, 1 month ago

    Reply
    Quote from: ddecjc at Apr 04, 2006, 07:01 AM
    I looked in document.parser.class.inc.php and found the source of the problem. It is on line 763 in the evalSnippets function.
    $tempSnippetParams = split($splitter, $tempSnippetParams);
    


    Try adding this line right before the line above with the split() call:

    $tempSnippetParams = html_entity_decode($tempSnippetParams, ENT_NOQUOTES, $this->config['etomite_charset']);
    


    This seems to work for me, but I haven't tested it exstensively yet. If that doesn't work, try simply turning off the rich-text editor for a moment and pasting the code directly into the content source. This will prevent the RTE from converting the special characters to HTML entities when being saved to the DB.


  • ddecjc Reply #6, 6 years, 1 month ago

    Reply
    Quote from: OpenGeek at Apr 04, 2006, 10:18 AM
    Try adding this line right before the line above with the split() call:
    $tempSnippetParams = html_entity_decode($tempSnippetParams, ENT_NOQUOTES, $this->config['etomite_charset']);
    That did the trick. Thanks!

    Quote from: OpenGeek at Apr 04, 2006, 10:18 AM
    If that doesn't work, try simply turning off the rich-text editor for a moment and pasting the code directly into the content source. This will prevent the RTE from converting the special characters to HTML entities when being saved to the DB.
    Doh! I didn't even think about it being stored that way because of the RTE. I was thinking that it got converted to html entity during parsing.

    Thanks again!


  • MrDutchy Reply #7, 4 years, 5 months ago

    Reply
    Why can't i call a snippet and initialize a parameter with a special character?
    like
    If i do in the snippet the variable content is truncated and if i return it, it is merely abc

    We're running 0.9.6 on PHP Version 5.2.3 so the fix discussed in this thread should be allready applied correct?
    However it looks like I still have trouble with this: http://modxcms.com/bugs/task/334


  • opengeek Reply #8, 4 years, 5 months ago

    Reply
    This has always been a known limitation of snippet parameter values; you cannot use ? & or =.

    The problem has been addressed for 0.9.7 release.


  • MrDutchy Reply #9, 4 years, 5 months ago

    Reply
    Quote from: OpenGeek at Dec 11, 2007, 10:14 AM
    This has always been a known limitation of snippet parameter values; you cannot use ? & or =.

    The problem has been addressed for 0.9.7 release.
    I was experiencing the bug with ñ, ¿, ¡, á and the list goes on, not just the operators you listed.
    Edit: just after posting it crossed my mind that every html encoded character obviously contains a & My bad
    I ended up doing what you described earlier in this thread (switching the MODx document to non-rte, save, replace the html encoded chars with non encoded versions, save, switch back to rte). Thank god it were only 3 pages this time around


  • sottwell Reply #10, 4 years, 5 months ago

    Reply
    That's the RTE being overly helpful; you can stop that in the plugin configuration; change one of the settings to 'raw' (I forget exactly which setting that is).

    Not being able to use & and = in snippet parameters is another matter; it has to do with how snippet parameters are parsed. You can work around that by making a "wrapper" snippet that only has
    $modx->runSnippet('snippetName', array('param1'=>'value1', 'param2'=>'value2'));
    return '';