Skip to content

Line breaks in meta values break wp post meta list #262

Closed
wp-cli/wp-cli
#6055

Description

@johnbillion

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.

Activity

  1. tfirdaus commented on Apr 9, 2024

    @tfirdaus

    @schlessera I was able to replicate this issue:

    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.

    Screenshot 2024-04-09 at 4 51 40 PM

    The output changes depending on the window size though, and it seems like the line break is simply replaced with a blank space? 🤔

    Screenshot 2024-04-09 at 4 54 18 PM

    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.

    What's your thought?

  2. BhargavBhandari90 commented on Mar 1, 2025

    @BhargavBhandari90
    Contributor

    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:

    Image

    After I modified Formatter.php

    Image

    PR I've created wp-cli/wp-cli#6055

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions