Piwigo / Piwigo-Mobile

Piwigo iOS Mobile Application
MIT License
100 stars 29 forks source link

Album description is not HTML decoded #464

Closed miklosbagi closed 3 years ago

miklosbagi commented 3 years ago

Describe the bug and how to reproduce Using special characters in Album description breaks the user experience in the mobile app as they don't they HTML decoded.

Steps to reproduce the behavior:

  1. Create a new album in Piwigo and add the following description (example): "Ünnepek"
  2. Save it, and open up the mobile app
  3. Navigate to a view where the album is visible with its description
  4. Observe that the app displays description as "\&\Ünnepek"

Expected behavior Enable HTML decode to album descriptions.

Screenshots

Screenshot 2021-07-31 at 12 33 33

Smartphone (please complete the following information):

Additional details Please note that the same behavior is observable when viewing the Album title on the Album view screen.

miklosbagi commented 3 years ago

Attempted a fix but got stuck, Halp! :)

Adding a simple HTML decoder helps: AlbumTableViewCell.m line 61

from:

    else {
        self.albumComment.text = self.albumData.comment;
        self.albumComment.textColor = [UIColor piwigoColorText];
    }

to:

    else {
        NSData* stringData = [self.albumData.comment dataUsingEncoding:NSUTF8StringEncoding];
        NSDictionary* options = @{NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType};
        NSAttributedString* decodedAttributedString = [[NSAttributedString alloc] initWithData:stringData options:options documentAttributes:NULL error:NULL];
        NSString* decodedString = [decodedAttributedString string];

        self.albumComment.text = decodedString;
        self.albumComment.textColor = [UIColor piwigoColorText];
    }

This seems to fix the iOS bit of the issue, well, somewhat. Please note the "ő" character at the end of the second line in the comment (screenshot in bug description). That character is not HTML encoded, so decoding with the above method will actually lead to breaking that.

JSON received for the album in question from /ws.php?format=json&method=pwg.categories.getList looks like:

      {
        "id": 31,
        "name": "Események",
        "comment": "\r\n\tÜnnepek, ballagások, szallagavatók, esküvők, tejfakasztók, és temetések\r\n",
        "permalink": null,
...

This is with content type text/plain; charset=utf-8.

So the question is:

EddyLB commented 3 years ago

Duplicate issue. See #324.