< 262022-05-27⋎28 >

Topic for #farmOS is: farmOS (farmos.org) is a free and open source, web-based farm management system. User guide: farmos.org/guide/ - Forum: farmOS.discourse.groupSet by mstenta on 2021-06-15 at 12:52
15:14symbioquine[m]I'm trying to figure out where the logic that drops the "Something: " prefix from assets names that appear in movement log names is implemented;
15:14*uploaded an image: (116KiB) < libera.ems.host/_matrix/media/r0/downloa >
15:15symbioquine[m]It doesn't seem to be [here](github.com/farmOS/farmOS/blob/04bf771d91)
15:15symbioquine[m]or [here](github.com/farmOS/farmOS/blob/04bf771d91)
15:15symbioquine[m]But naively, we'd imagine the log name would be `"Move Tractor: Slow Red to Big Field A, Big Field B"`
15:19symbioquine[m]It actually seems like pretty decent/sane behavior, but it feels a bit towards the "conventions" side of things...
15:20symbioquine[m]i.e. how does someone choosing their conventions know that farmOS provides that "feature" if they name their assets with the "Something: " prefix pattern?
15:31mstenta[m]symbioquine: is this what you're looking for? github.com/farmOS/farmOS/blob/81da2ed9b3
15:31mstenta[m]`$log_name = $this->t('Move :assets to :locations', [':assets' => $asset_names, ':locations' => $location_names]);`
15:32mstenta[m]oh wait no
15:32mstenta[m]that's what you linked to above
15:32symbioquine[m]Maybe. Does Drupal do some magic when doing those string substitutions?
15:32symbioquine[m]That would seem surprising.
15:32mstenta[m]i'm not sure i follow
15:32mstenta[m]oooooh i see what you mean!
15:33mstenta[m]that is a bug!
15:33mstenta[m]i think paul121 actually just discovered this in another context recently!
15:33mstenta[m]yes, we need to change that line (that i pasted above) so that it uses `@` instead of `:` for the placeholdres
15:33symbioquine[m]mstenta[m]: Interesting!
15:33mstenta[m]care to open a PR? :-)
15:34mstenta[m]i forget exactly why, but we realized this recently... paul121 may have actually found this one too - i think he did a grep for other occurrences so we could fix all of them
15:34symbioquine[m]Sure, I can do that...
15:34symbioquine[m]Is there an issue already?
15:35mstenta[m]i don't think so
15:35mstenta[m]api.drupal.org/api/drupal/core%21lib%21D
15:35mstenta[m]describes the different filtering that takes place with `@` vs `:`
15:36mstenta[m]> `:variable`: Return value is escaped with \Drupal\Component\Utility\Html::escape() and filtered for dangerous protocols using UrlHelper::stripDangerousProtocols(). Use this when using the "href" attribute, ensuring the attribute value is always wrapped in quotes:
15:36mstenta[m]that should only be used in `href`... not in normal strings (eg log names)
15:36symbioquine[m]hahaha, yeah I see how it's definitely a bug in this context
15:36symbioquine[m]If we wanted that behavior, we wouldn't do it that way :)
15:36mstenta[m]yup
15:37mstenta[m]just fat fingers / laziness / forgetfulness about the differences
15:37mstenta[m](i've made this mistake before... i'm usually careful about it... guess this one slipped through)
15:39mstenta[m]paul121: do you remember talking about this recently? where was the one you discovered, do you recall? and did you find others?
15:39symbioquine[m]Cool, maybe there's a way we can add a code sniffer style rule about it...
15:39mstenta[m]yea
15:39mstenta[m]surprised there isn't already!
15:39mstenta[m]maybe it's hard to scan for
15:39mstenta[m]🤷
15:40symbioquine[m]might be that
15:59paul121[m]<mstenta[m]> "paul121: do you remember talking..." <- yup! when you use the `:` placeholder it expects that you are giving it a URL and it does some logic to remove everything before the last `:`. I forget why
16:00symbioquine[m]<mstenta[m]> "> `:variable`: Return value is..." <- Vaguely this is why ^
16:00paul121[m]yea, I guess that would be hard because codesniffer needs to understand the context for the parameter
16:01paul121[m]normally '@` would be used like this: `$this-t('Here is a <a href="@url">link</a>', ['@url' => 'farmos.org']);`
16:01paul121[m] * normally `@` would be used like this:`$this-t('Here is a \<a href="@url">link\</a>', \['@url' => 'farmos.org'\]);\`
16:02paul121[m] * normally `@` would be used like this:`$this-t('Here is a <a href="@url">link</a>', \['@url' => 'farmos.org'\]);\`
16:03paul121[m]but you might use it in other ways as well 🤷
16:03paul121[m]<mstenta[m]> "i forget exactly why, but we..." <- our bug was in the Rothamsted code :-)
16:04symbioquine[m]paul121[m]: But is there a scenario is farmOS where we'd want that escaping behavior?
16:06symbioquine[m]I think it would be much easier to have a check for any use of the colon substitution patterns.
16:07paul121[m] * normally `:` would be used like this:`$this-t('Here is a <a href=":url">link</a>', \[':url' => 'farmos.org'\]);\`
16:07paul121[m]oh oops I had it backwards
16:09paul121[m]yeah good question
16:09paul121[m]can we always expect the `:` replacement to be within an anchor tag?
16:12paul121[m]I did a quick search... that seems to be the case
16:12paul121[m]I found a few other instances in the planting quick form: github.com/farmOS/farmOS/blob/81da2ed9b3
16:34symbioquine[m]<paul121[m]> "can we always expect the..." <- I'm not sure the detection logic would need to be that context aware. If we can say that code in the farmOS code-base should almost always use `@` substitutions, then we could just use `grep` to do the detection and maybe check the preceding line for a pragma like;
16:34symbioquine[m]```php
16:34symbioquine[m]//# next-line-intentional-use-of-colon-translation-substitution
16:34symbioquine[m]```
16:42paul121[m]oh true!
16:44mstenta[m]Is there any detection already to ensure that hrefs use a colon?
16:44mstenta[m]That is the more critical thing from a security perspective
16:44paul121[m]right now I use the same farmOS 2.x-dev image & phpcs rules in my contrib module template. for better or worse, this would cascade to those repos as well.... it would be nice if the change didn't require adding the comment, but doesn't mean I'm totally against that :-)
16:45mstenta[m]Should check to see if this has been discussed upstream
16:45mstenta[m]I have to imagine it has
17:27symbioquine[m]farmos.discourse.group/t/asset-link-dev- 🎉
22:24*EvanKelley[m] has quit (Ping timeout: 240 seconds)
22:37*EvanKelley[m] has joined

< 262022-05-27⋏28 >