Problem/Motivation
"description" Meta tag from token "[node:summary]" is resulting in linebreaks in code. I guess meta tag values should have no line breaks?
Possibly related Drupal 7 issue: #1978568: Don't output line breaks in meta tags
Steps to reproduce
Write node entry with line breaks in summary
Set up Node meta tag for Meta description
Set "[node:summary]" as value
Check source and see the line breaks
Proposed resolution
Filter line breaks before output
Remaining tasks
User interface changes
API changes
Data model changes
Issue fork metatag-3218647
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
damienmckennaThis should be added to MetaNameBase::output().
Comment #4
damienmckennaComment #5
damienmckennaSome test coverage would be useful, to make sure this works as expected.
Comment #7
luisrhaas commentedI created a method to allow subclasses implement a custom filter when it is necessary. Please review.
Comment #8
damienmckennaThat's a good start, but can you please move the logic back into the parent MetaNameBase meta tag? There's no point in having to do this on a per-tag basis.
Comment #9
luisrhaas commentedHi Damien! I did a new commit moving the logic to parent class, please let me know if now the solution is ok.
I did that to avoid affect any other class which extends MetaNameBase.
Comment #10
damienmckennaThe only issue I can see with this is that meta tags with URLs to file names which include multiple concurrent spaces would have problems, but honestly that's something sites should resolve using something like Transliterate Filenames.
Beyond that, this looks good.
Now for some test coverage.
Comment #11
anybodyJust one crazy idea outside the box... (may really be nonsense ;) )
Allow to use a text format (input filter) to let the user control the behavior wouldn't make sense, would it? I tend to say it would only further complicate things, but thought it would be worth to write down that idea... ;D
Comment #12
damienmckenna@Anybody: No, that wouldn't fix the underlying problem and would just make it more complicated to manage.
Comment #13
luisrhaas commentedHi Damien!
I made a unit test for the new function filterValue, please let me know if it's ok.
Comment #14
damienmckennaOther than some minor whitespace / coding standards corrections, this looks great!
Idea - let's combine all the logic into the existing tidy() method.
Comment #15
luisrhaas commentedHi Damien! Coding standard fixed, please check.
Comment #16
luisrhaas commentedChanging to needs review
Comment #17
damienmckennaThat's better, thank you.
The logic needs to be moved into the tidy() method.
Comment #18
luisrhaas commentedHi Damien! I moved all the logic to tidy function and fixed the tests, thank you for the support
Comment #19
damienmckennaExcellent! I love it!
I'll work on the comments a little prior to committing it, but otherwise this is perfect.
Comment #21
damienmckennaCommitted, with some comment improvements. Thank you!
Comment #22
anybodySo great to see, thank you both very very much!
Comment #24
idebr commentedIn addition to line breaks, meta tag output is now also cleared on duplicate spaces. This is a BC break for projects that implemented a custom filter for empty elements in the output, eg:
Comment #25
anybodyThank you for your feedback @idebr - any suggestion how to solve this for all cases? I'm not sure what's worse...
Perhaps add a setting or config value to disable cleanup? I guess for most cases (as metatag is based on token, which tend not to be "clean") a cleanup is more useful than double blanks like in the edge-case?
Another alternative that comes to my mind would be to run the hook later or add a further later hook?
Comment #26
lendudeWell the point of this issue was to remove newlines from the output, so why are we stripping double whitespace characters here?
From just reading this issue, this seems out of scope and potentially not needed at all. Or are double whitespace characters violating some metatag markup standards?
Comment #27
damienmckennaIt's common practice to replace line breaks with a space, to make sure that sentences have a gap between them. It's also common to find extra spaces after the last period in a paragraph. Put these together and multiple concurrent spaces can be a side effect of joining paragraphs together. So then we strip out multiple spaces so that there's only one space separating sentences. This is a common practice and actually brings it in line with Metatag on D7.
I'm sorry this resulted in a subtle break in backwards compatibility for your sites. Looking at the custom code provided in #24 it should be simple to adjust to the new logic. FWIW we won't be reverting this change, and making it optional is over-engineering the problem and unnecessary, but I thank you for raising the point.