You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Line breaks in meta values break wp post meta list #262
Given a post meta field with a value that contains line breaks, the output of wp post meta list breaks. Example:
$ wp post meta list 123
+---------+----------+------------+
| post_id | meta_key | meta_value |
+---------+----------+------------+
| 123 | foo | foo |
| 123 | bar | bar
bar
bar
bar
bar
bar |
| 123 | baz | baz |
+---------+----------+------------+
Should this output be improved? A potential improvement would be:
+---------+----------+------------+
| post_id | meta_key | meta_value |
+---------+----------+------------+
| 123 | foo | foo |
| 123 | bar | bar |
| | | bar |
| | | bar |
| | | bar |
| | | bar |
| 123 | baz | baz |
+---------+----------+------------+
This might be difficult to implement though.
Note: The wp post get command doesn't suffer from this problem, which means line breaks in the post_content field don't break the output.
001 Scenario: List post meta with line break value # features/post-meta.feature:492
Then STDOUT should be a table containing rows: # features/post-meta.feature:503
post_id meta_key meta_value
1 foo bar
bar
bar
(Exception)
But looks like we're facing a similar issue with the post list command as well.
The output changes depending on the window size though, and it seems like the line break is simply replaced with a blank space? 🤔
Handling the line break might be difficult, as @johnbillion mentioned. However, we could probably consider making a compromise by replacing the line break with a blank space in the table format. I haven't checked the JSON and YML formats, but I believe retaining the line break in those two formats would be much simpler.
Activity
tfirdaus commentedon Apr 9, 2024
@schlessera I was able to replicate this issue:
But looks like we're facing a similar issue with the
post listcommand as well.The output changes depending on the window size though, and it seems like the line break is simply replaced with a blank space? 🤔
Handling the line break might be difficult, as @johnbillion mentioned. However, we could probably consider making a compromise by replacing the line break with a blank space in the
tableformat. I haven't checked the JSON and YML formats, but I believe retaining the line break in those two formats would be much simpler.What's your thought?
BhargavBhandari90 commentedon Mar 1, 2025
Hi I tried to fix this issue, but for that I had to modify https://github.com/wp-cli/wp-cli/blob/main/php/WP_CLI/Formatter.php from code wp-cli file.
Not sure if this is the right approach or not. But result is expected.
Before:
After I modified
Formatter.phpPR I've created wp-cli/wp-cli#6055
Properly handle line breaks in column value
Properly handle line breaks in column value (#179)