[B3.1][ML/MS] OpenLink() uses wrong encoding (ISO, not UTF8)

Moderator: NADEO

Locked
User avatar
m4rcel
Posts: 650
Joined: 15 Jun 2010, 11:12
Contact:

[B3.1][ML/MS] OpenLink() uses wrong encoding (ISO, not UTF8)

Post by m4rcel »

When opening a link using OpenLink() in ManiaScript, the script fails to correctly encode the URL and its parameters.

See the following test script:

Code: Select all

<?php

$script = 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['SCRIPT_NAME'];
$param = htmlspecialchars(isset($_GET['param'])? $_GET['param'] : '', ENT_QUOTES, 'UTF-8');

header('Content-Type: text/xml;charset=utf-8');
echo <<<EOT
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<manialink version="1" background="0">
   <entry id="entry" name="inputParam" sizen="100 5" default="Some special characters: äöüß 日本語"/>
   <label id="label" posn="0 -10" style="CardButtonMediumWide" text="Send! (with ManiaScript)" ScriptEvents="1" />
   <label posn="0 -20" style="CardButtonMediumWide" text="Send! (with label-manialink)" manialink="{$script}?param=inputParam" />
   <label posn="0 -30" textcolor="000F">{$param}</label>
   <script><!--
while(True) {
   foreach(Event in PendingEvents) {
      if (Event.Type == CGameManialinkScriptEvent::Type::MouseClick && Event.ControlId == "label") {
         declare Text Link = "{$script}?param=" ^ (Page.GetFirstChild("entry") as CGameManialinkEntry).Value;
         log("OpenLink: " ^ Link);
         OpenLink(Link, ::LinkType::ManialinkBrowser);
      }
   }
   yield;
}
--></script>
</manialink>
EOT;

?>
The value of the entry is appended to the URL as a parameter. When using the "classic" method, the manialink-attribute of a Control, the encoding is UTF8, which is correct. But as soon as you use the Entry-value in OpenLink(), the encoding falls back to ISO-8859-whatever, having the specialk characters destroyed.


Already heard of that bug? Then you may remember my bug report over a year ago, yet it still persists... How about eventually fixing it? :D
ImageImage
Image
User avatar
Gugli
Nadeo
Nadeo
Posts: 536
Joined: 14 Jun 2010, 17:35
Location: Mon PC est à Paris, mais mon coeur rode dans les forêts de Lozère

Re: [B3.1][ML/MS] OpenLink() uses wrong encoding (ISO, not U

Post by Gugli »

Thank for you report.

The problem was a function missing in TextLib.

I can not encode the whole URL : if the URL is "http://localhost/test.php?param1=value1&param2=value2", you don't want the "?", the "=" or the "&" to be encoded, but only "value1" and "value2"

You will have to encode the parameters yourself in the script by calling the brand new function : TextLib::URLEncode(...)

Code: Select all

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<!-- http://localhost/TestOpenLink.xml -->
<manialink version="1" background="0">
   <entry id="entry" name="inputParam" sizen="100 5" default="Some special characters: äöüß 日本語"/>
   <label id="label" posn="0 -10" style="CardButtonMediumWide" text="Send! (using ManiaScript)" ScriptEvents="1" />
   <label posn="0 -20" style="CardButtonMediumWide" text="Send! (using classic method)" manialink="http://localhost/TestOpenLink.xml?param=inputParam" />
   <label posn="0 -30" textcolor="000F">param</label>
   <script><!--
#Include "TextLib" as TextLib
while(True) {
   foreach(Event in PendingEvents) {
      if (Event.Type == CMlEvent::Type::MouseClick && Event.ControlId == "label") {
         declare Text Link = "http://localhost/TestOpenLink.xml?param=";
         Link ^= TextLib::URLEncode((Page.GetFirstChild("entry") as CMlEntry).Value); // It works now !
         log("OpenLink: " ^ Link);
         OpenLink(Link, ::LinkType::ManialinkBrowser);
      }
   }
   yield;
}
--></script>
</manialink>
Thanks again for your report. The function TextLib::URLEncode() will be shipped with the next update.
--
(>~_~)> ═╦═ ╔╦╗ <(~_~<)
User avatar
steeffeen
Translator
Translator
Posts: 2463
Joined: 14 Oct 2012, 16:22
Location: Germany

Re: [B3.1][ML/MS] OpenLink() uses wrong encoding (ISO, not U

Post by steeffeen »

that's great! :yes:

Gugli, you're doing quite some work today :lol:
    Game Mode and Title Pack Creator, Developer, ShootMania-Player & more

    ManiaControl, FancyManiaLinks
    User avatar
    Gugli
    Nadeo
    Nadeo
    Posts: 536
    Joined: 14 Jun 2010, 17:35
    Location: Mon PC est à Paris, mais mon coeur rode dans les forêts de Lozère

    Re: [B3.1][ML/MS] OpenLink() uses wrong encoding (ISO, not U

    Post by Gugli »

    steeffeen wrote: Gugli, you're doing quite some work today :lol:
    I should have done most of this much earlier :S.

    I've also done a long-overdue chat-accounts migration ^_^.

    Let's call it a night ! Have fun ingame ;)
    --
    (>~_~)> ═╦═ ╔╦╗ <(~_~<)
    User avatar
    spaii
    Posts: 1075
    Joined: 19 Jun 2010, 00:04
    Location: Rémy - France
    Contact:

    Re: [B3.1][ML/MS] OpenLink() uses wrong encoding (ISO, not U

    Post by spaii »

    Nice !! :thumbsup:
    Locked

    Return to “Maniaplanet Reports”

    Who is online

    Users browsing this forum: No registered users and 1 guest