return temp + url;
}
+
void InsetHyperlink::doDispatch(Cursor & cur, FuncRequest & cmd)
{
switch (cmd.action()) {
// For the case there is no name given, the target is set as name.
// Do this before !url.empty() and !name.empty() to handle characters
- // like the "%" correctly.
+ // such as % correctly.
if (name.empty())
name = url;
if (!url.empty()) {
- // Replace the "\" character by its ASCII code according to the
- // URL specifications because "\" is not allowed in URLs and by
- // \href. Only do this when the following character is not also
- // a "\", because "\\" is valid code
+ // Use URI/URL-style percent-encoded string (hexadecimal).
+ // We exclude some characters that must not be transformed
+ // in hrefs (% # / :) or that we need to treat manually (\).
+ url = to_percent_encoding(url, from_ascii("%#\\/:"));
+ // We handle \ manually since \\ is valid
for (size_t i = 0, pos;
(pos = url.find('\\', i)) != string::npos;
i = pos + 2) {
// field because otherwise LaTeX will fail when the hyperlink is
// within an argument of another command, e.g. in a \footnote. It
// is important that they are escaped as "\#" and not as "\#{}".
+ // FIXME this is not necessary in outside of commands.
for (int k = 0; k < 2; k++)
for (size_t i = 0, pos;
(pos = url.find(chars_url[k], i)) != string::npos;
}
+docstring to_percent_encoding(docstring const & in, docstring const & ex)
+{
+ QByteArray input = toqstr(in).toUtf8();
+ QByteArray excludes = toqstr(ex).toUtf8();
+ return qstring_to_ucs4(QString(input.toPercentEncoding(excludes)));
+}
+
+
docstring bformat(docstring const & fmt, int arg1)
{
LATTEST(contains(fmt, from_ascii("%1$d")));
/// like "1000000.000000", and precision control would not be that easy either.
std::string formatFPNumber(double);
+/// Returns an URI/URL-style percent-encoded copy of the string \p in.
+/// \p ex defines a string of characters that are excluded from the transformation
+docstring to_percent_encoding(docstring const & in, docstring const & ex = docstring());
+
docstring bformat(docstring const & fmt, int arg1);
docstring bformat(docstring const & fmt, long arg1);