eduardoboucas/staticman

Fix line-break formatting in pull requests

klundberg opened this issue · 5 comments

I just got this PR from staticman: klundberg/klundberg.com#4


~~~I apologize if this already exists and I don't have my site properly configured, but when I set things up I didn't see anything along these lines of only allowing specific form fields to be sent.~~~

My mistake, it's seems like there was no clever spammer behavior here that can be easily prevented. The problem here that confused me appears to be that the line breaks in the message mess up formatting of the PR, which made it look like there were extra form fields added to embed some targeted spam only intended for blog owners. The message in that PR should probably fit entirely inside one markdown table cell, if that's possible to do.

Thank you!

I can confirm this.

But it can be solved easily, when generating a table:

staticman/lib/Staticman.js

Lines 201 to 203 in ecf0386

Object.keys(fields).forEach(field => {
table.push([field, fields[field]])
})

Just remove new lines and replace them with breaks <br />.

  Object.keys(fields).forEach(field => {
    table.push([field, fields[field].replace(/\n/gm, '<br />')])
  })

Afaik this is the only way to add newlines to a markdown table.

I will do a PR for this soon.
EDIT: This is a one line fix, but I'm not sure how to test it before making a PR :/

Bump, any news on this one?

Just got two comments with the same issue, and each of them renders differently. One looks exactly same like the PR in @klundberg 's repo. And the other look like this:

image

Furthermore, I don't understand where the fields tags and layout came from. I've never configured them in allowedFields in staticman.yml.

@JokerQyou The code is only replacing LF, but I suspect your example had CR/LF. In PR #289 I chained two calls to replace to handle both scenarios.

@BloggerBust-bot Your PR contains an unnecessary dependence on #285, so I created another one for the convenience of v3 users. Anyways, great work!