Closed (fixed)
Project:
Service links
Version:
7.x-2.x-dev
Component:
Code
Priority:
Major
Category:
Bug report
Assigned:
Reporter:
Created:
3 Nov 2011 at 17:51 UTC
Updated:
19 Mar 2013 at 20:10 UTC
Jump to comment: Most recent file
I am having some problems with the encoding of some titles sent to various services. For example, if the node title contains an apostrophe, such as
node' title
The service (verified with twitter and delicious.com) prompts for the following title:
node' title
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | 1330830-5.service-links-proper-title-encoding.patch | 300 bytes | dww |
| #2 | service_links-1330830-7.x.patch | 287 bytes | TheCrow |
| #1 | service_links-1330830.patch | 287 bytes | TheCrow |
Comments
Comment #1
TheCrow commentedA patch to test
Comment #2
TheCrow commentedThis is for 7.x-2.1
Comment #3
an_mo commentedthe patch for drupal 6 works for me/
thanks
Comment #4
Feet commentedPatch in #1 for D6 works great for me
Comment #5
dwwJust marked #1645488: Twitter posts ' instead of apostrophes duplicate. I'm hitting the same bug.
Part of me thinks this is a deeper problem of double encoding. Ultimately, you're always populating $links to be used via
theme('links', $links), and stuffing the query (after custom string manipulation to split the URL at ?) into$link['query']as a single string. However, theme_links() eventually calls url() which will encode the query for you via drupal_query_string_encode() (oh, only if it's an array, hrm). ;) Heh, never mind. Although, it does make me wonder if it wouldn't be easier to just propagate all the query strings around via arrays since that'd make it easier to alter, would avoid a bunch of complicated string manipulation, and would allow core to handle the encoding properly for us instead of trying to do it all ourselves...Anyway, patch #2 is not the right fix.
_service_links_get_node_title()is only called by_service_links_get_tags()which is using it to populate all the various tokens for replacing URLs. These values aren't being rendered as HTML (in which case, check_plain() would be be appropriate), but are being used inside URLs. So, we needrawurlencode()and friends, notcheck_plain(). Which is exactly what we're calling in those cases. The raw<title>is raw (and according to grep, unused, anyway).My attached patch is a better approach. Just return the
$titledirectly, don't try to modify it at all, and letrawurlencode()do the right thing.check_plain()only makes sense for displaying untrusted text to a browser, not for building URLs. I recommend http://acko.net/blog/safe-string-theory-for-the-web if you haven't already read it.I've tested this with a node titled
Testing <script>alert('xss')</script> titleand it all works as expected. No XSS alert thrown, URLs are proper, and it shows up correctly inside Twitter's tweet composing text area once you follow the service link to twitter.BTW, this patch applies cleanly to both 7.x-2.x and 6.x-2.x.
Thanks!
-Derek
Comment #6
BeaPower commentedwhen will these be committed, having problems in current d7 version... 7.x-2.1
Comment #7
dww@BeaPower: They'll be committed once there are sufficient reviews and testing of the patches that the maintainer feels confident in them. You could help with this by testing the patch on a dev site for your site and reporting the results here.
Thanks,
-Derek
Comment #8
matmasr commentedI have been experiencing a similar issues with Views 7.x-3.3. I have a view that is filtering nodes based on a taxonomy term. In that page layout, I have chosen to override the page title with my context argument "%1" which refers to the taxonomy term.
When a taxonomy term has a single quote ', it is displayed as ' instead. Also, the "&" character is showing up as &Amp; instead. I believe this may be a Views bug ?
Comment #9
dww@matmasr: Please search in the views issue queue for an existing bug report about that and follow that issue. This issue is strictly about service_links, not views.
Thanks,
-Derek
Comment #10
matmasr commented@dww ... thanks for the note. Apologies for posting here. Just though this is a common bug, independent of Views or service_links. I did post again at in Views issues que
Comment #11
sjancich commentedPatch in #5 worked for me!
Comment #12
simon georges commentedChanging version during issue queue cleaning.
Comment #13
simon georges commentedSeveral people confirmed it works.
Comment #14
TheCrow commentedPushed #5!
Comment #15
dwwHurray, thanks!
Comment #16.0
(not verified) commentedadded code tags to escape the bug report so we actually see what the bug is. ;)