Closed (fixed)
Project:
Drupal core
Version:
8.0.x-dev
Component:
tour.module
Priority:
Major
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
14 Jun 2013 at 08:36 UTC
Updated:
29 Jul 2014 at 22:31 UTC
Jump to comment: Most recent file
Comments
Comment #1
clemens.tolboomComment #2
gábor hojtsyWoot! Needs tests :)
Comment #3
clemens.tolboomWhat test do we need? We just call
\Drupal::token()->replace()which is tested through core/modules/system/lib/Drupal/system/Tests/System/TokenReplaceTest.phpI'm not sure what other tests we could create?
Comment #4
gábor hojtsyHave a tour body that has a token that is replaced?
Comment #5
clemens.tolboomAttached patch has a Token replacement test added.
Comment #6
gábor hojtsyTest looks good to me :) This feature will be vital to add links to tips for example where the website URL could need any path prefix.
Comment #7
larowlanUnless bot disagrees
Great work
Comment #8
gábor hojtsy+1
Comment #9
alexpottCommitted e89fbf3 and pushed to 8.x. Thanks!
Comment #10
pwieck commentedI have just pulled the latest release and using tokens in tours is not working correctly.
Example:
Does the small thing if you use [site:name] as in the test. You get 'name]' as the output.
Comment #11
clemens.tolboom@pwieck thanks for reporting.
I guess you found a bug in token replacement.
Changing the test for our tour into
outputs indeed wrong replacement with leftover "url]"
Adding this (see attachment) to core/modules/system/lib/Drupal/system/Tests/System/TokenReplaceTest.php does not result into the mentioned error (containing a leftover ]) :(
Test result snippet while running System/Token replacement:
<td>Valid tokens replaced while invalid tokens cleared out.<blink>Blinking Text</blink>v8prvVbr0 secadmin06/17/2013 - 08:26<a href="http://drupal.d8//admin/config/regional/language">add a language</a></td>I'm puzzled :/
Comment #12
pwieck commentedAny progress on this so we can start tours that need links?
Comment #13
larowlanI have fix, will sort in next 20 min
Comment #14
larowlanFirst a fail to demonstrate that the url token doesn't work.
Then a pass.
Whilst I was at it I removed the call to \Drupal from inside the plugin and injected the token service (which is the right way to do it, calling out to \Drupal is frowned upon from OO code) and re-ordered the use statements into alpha.
Basic difference was filter_xss_admin had to go after token replacement, not before.
Comment #15
clemens.tolboom@larowlan do you know why it failed? I still suspect a bug in token somehow.
Patch from #14 looks ok to me. It's very instructive too :)
I guess this change should be done to TipPluginImage too which resides in the tests.
I'm not sure this swapping is ok for tours. Are tokens XSS save or not? The new line will ie filter out images which tour could use.
Comment #16
larowlanIt failed because filter_xss_admin strips stuff before token.
outputs
Doing it the other way is fine, filter_xss_admin only strips XSS attacks so if you're doing nothing wrong, nothing to fear.
outputs
(my dev site is d82.taco)
That fail count is wrong, random failures - should only be 1 - I will re-test.
We don't need to make the changes to the image tip, it doesn't need injected services from the container.
Comment #17
larowlan#14: tour-token-2019469.fail_.patch queued for re-testing.
Comment #18
clemens.tolboom@larowlan thanks for explaining :)
I'm still puzzled as
-
[site:name]passes the test in #5 while[site:url]fails- Reading https://api.drupal.org/api/drupal/core!includes!common.inc/function/filt... the img tag is not allowed.
Comment #19
larowlanWe use filter_xss_admin, not filter_xss :).
The difference with [site:url] is its inside a href attribute, filter_xss_admin sanitizes the href against malicious urls.
outputs [site:url]
Comment #20
gábor hojtsyLooks like a great fix! Good find on the bug :)
Comment #21
alexpott@larowlan considering you are making the effort to make the tour plugin manager use the ContainerFactory how about converting the manager to extend Drupal\Core\Plugin\DefaultPluginManager?
Leaving at rtbc in case you consider this out-of-scope...
Comment #22
alexpottOut discussed this with @larowlan in IRC decided that converting the manager to DefaultPluginManager is out of scope...
Committed 7979dcd and pushed to 8.x. Thanks!
.