Issue Details (XML | Word | Printable)

Key: MDL-13975
Type: Bug Bug
Status: Reopened Reopened
Priority: Minor Minor
Assignee: Petr Skoda
Reporter: Nicolas Martignoni
Votes: 0
Watchers: 2
Operations

Add/Edit UI Mockup to this issue
If you were logged in you would be able to see more operations.
Moodle

p() and s() should not be used to print lang strings

Created: 19/Mar/08 07:08 PM   Updated: 06/Nov/09 02:50 AM
Return to search
Component/s: Languages, Lib
Affects Version/s: 1.9.3
Fix Version/s: None

Issue Links:
Relates

Participants: Dongsheng Cai, Nicolas Martignoni, Petr Skoda and Tim Hunt
Security Level: None
QA Assignee: Dongsheng Cai
Resolved date: 19/Mar/08
Affected Branches: MOODLE_19_STABLE


 Description  « Hide
HTML entities like   or   don't get parsed by function p() and print litteraly, e.g. $string['usergroupmembership'] in group/members.php, line 281.

 All   Comments   Change History   Version Control      Sort Order: Ascending order - Click to sort in descending order
Nicolas Martignoni added a comment - 19/Mar/08 07:17 PM
After more inspection, it turns out that the only entities that are parsed are in the form &#ddd;, where the d's are digits. The & is not parsed, but printed instead.

Petr Skoda added a comment - 19/Mar/08 07:44 PM
the p() and s() are not designed to print html with tags & etc., it is for plaintext and form values mostly, looking at this now...

Petr Skoda added a comment - 19/Mar/08 07:49 PM
fixed the members.php - uses echo() now
please reopen if there are more similar problems,
thanks for the report!

Nicolas Martignoni added a comment - 19/Mar/08 10:03 PM
Thanks for the quick fix. Verified. I don't close this as I'm pretty sure that there are other instances of this issue.

NB Should the developer docs be updated with this info about p() and s()?


Petr Skoda added a comment - 20/Mar/08 02:04 AM
Yes, please fix the docs if you can

Nicolas Martignoni added a comment - 20/Mar/08 02:12 AM

Dongsheng Cai added a comment - 14/May/08 11:00 AM
Thanks, Petr

Nicolas Martignoni added a comment - 12/Aug/08 02:21 AM
Reopening as s() is used in admin/uploaduser.php to print status messages, see e.g. function track() of class uu_progress_tracker.

Tim Hunt added a comment - 02/Nov/08 09:11 AM
I think if we are being strict, in XHTML, in browsers that treat the content as XML and which do not parse the DTD, then   will not work, so it is always safer to use numeric entities like  . Or since all lang files are UTF-8 anyway, just put the characters in them directly.

Anyway, I suppose the issue is: what do lang strings contain? Is it plain text, or HTML source? I guess it is HTML source, in which case the rule should be numeric entities only (plus the three that are included in XML: <, >, &, ', ").

However, when lang strings are output as attribute values in the HTML, it is essential that ' and " are output as ' and ", and that is certainly not the case in any language pack I have seen. Therefore the strings need to be fed through a function to escape them, and s() and p() are Moodle's standard function for doing this, and we seem to have come full circle.

Please someone explain to me!


Nicolas Martignoni added a comment - 02/Nov/08 08:28 PM
Hi Tim!

I too would prefer UTF-8 chars directly in lang files, but for some reason (sprintf lacking support of multibyte chars) the UTF-8 non-breaking space chars breaks lang strings. See MDL-6688 (still reproducible as of 2.0dev) that was only worked around preserving the   entities in lang files.

Otherwise, we should instruct lang pack maintainers, including myself , to always use numerical entities.


Nicolas Martignoni added a comment - 22/Nov/08 07:56 AM
The numeric entities are too not parsed by p() and s().

Nicolas Martignoni added a comment - 10/Apr/09 04:25 PM
Now that MDL-17358 is closed (and we now why), couldn't we close this as "not a bug" (see Tim comment) and instruct translators to use exclusively UTF-8 chars in the strings of the lang packs?

Nicolas Martignoni added a comment - 06/Nov/09 02:50 AM
Adding David as a watcher, re chat discussion about entities.