2

Maybe it's a known bug (I tagged it as a bug) or it is intentional.
I often find myself advicing less experienced user to read this page:

http://developer.android.com/reference/android/widget/TextView.html#setCompoundDrawablesWithIntrinsicBounds(int, int, int, int)

As you can see, the link is interrupted at the first occurrence of a comma.
It would be nice to see the link complete.

And, even worse, the link is truncated so that only this page is shown:

http://developer.android.com/reference/android/widget/TextView.html

and not the section to which I wanted the users to focus.

2
  • 1
    I should mention that this also breaks linking text (like this), so it's actually not possible to use that link unless you manually escape the url. Commented Mar 6, 2015 at 14:28
  • Exactly. You found better words than mine! Commented Mar 6, 2015 at 14:29

2 Answers 2

4

The reason is the space. It is unsafe to use space characters in URIs exactly because of this reason, it breaks on most text parsing systems.

Unless there is a special markup set, the parser does not know when the link stops. In order to avoid making everything after the text link a hyperlink, it stops at the first space.

It is always advised to encode unsafe characters. In this case space should become %20.

http://developer.android.com/reference/android/widget/TextView.html#setCompoundDrawablesWithIntrinsicBounds(int,%20int,%20int,%20int)

Workaround:

The hyperlink button from the editor will do this automatically if you insert an URL with unsafe characters. Using the following link ....

http://developer.android.com/reference/android/widget/TextView.html#setCompoundDrawablesWithIntrinsicBounds(int, int, int, int)

..will result in a working and encoded hyperlink

[enter link description here][1]

[1]: http://developer.android.com/reference/android/widget/TextView.html#setCompoundDrawablesWithIntrinsicBounds(int,%20int,%20int,%20int)

Modern browsers (or just Chrome?) tend to ignore this and display real spaces in the URI box. It is not safe however to use them everywhere.

2
  • Great explanation, thank you. It would be great if SO had the ability of replacing spaces with the %20 sequence in links. In both answers and comments, too. Commented Mar 7, 2015 at 7:09
  • Firefox does that too, although copying out of the address bar will keep the encoded URL. Commented Mar 9, 2015 at 14:22
0

This is by design, we need some characters to mark the end of a URL and one such character is space. Using spaces is unsafe in URIs because this is such a common issue.

One way to go around it is encoding the spaces, and http has a special placeholder for space: "+"

http://developer.android.com/reference/android/widget/TextView.html#setCompoundDrawablesWithIntrinsicBounds(int,+int,+int,+int)

which of course you can/should beautify with a proper link

[TextView](http://developer.android.com/reference/android/widget/TextView.html#setCompoundDrawablesWithIntrinsicBounds(int,+int,+int,+int))

resulting in

TextView

3
  • It again brought me to TextView... :( The %20 solution given by @Spokey works, though. Commented Mar 9, 2015 at 13:50
  • @DerGolem that's where it should take you, the second part after the # is an anchor within the page.
    – Sklivvz
    Commented Mar 9, 2015 at 13:51
  • Which is where I want to go: to the anchor. Like this Commented Mar 9, 2015 at 13:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .