Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: do not allow image markdown in assertions and command log #17777

Merged
merged 1 commit into from
Aug 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions packages/driver/cypress/integration/commands/assertions_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1197,6 +1197,20 @@ describe('src/cy/commands/assertions', () => {
})
})
})

describe('escape markdown', () => {
// https://github.com/cypress-io/cypress/issues/17357
it('images', (done) => {
const text = 'hello world ![JSDoc example](/slides/img/jsdoc.png)'
const result = 'hello world ``![JSDoc example](/slides/img/jsdoc.png)``'

expectMarkdown(
() => expect(text).to.equal(text),
`expected **${result}** to equal **${result}**`,
done,
)
})
})
})

context('chai overrides', () => {
Expand Down
6 changes: 6 additions & 0 deletions packages/driver/src/cy/chai.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const leadingWhitespaces = /\*\*'\s*/g
const trailingWhitespaces = /\s*'\*\*/g
const whitespace = /\s/g
const valueHasLeadingOrTrailingWhitespaces = /\*\*'\s+|\s+'\*\*/g
const imageMarkdown = /!\[.*?\]\(.*?\)/g

let assertProto = null
let matchProto = null
Expand Down Expand Up @@ -130,6 +131,10 @@ chai.use((chai, u) => {
})
}

const escapeMarkdown = (message) => {
return message.replace(imageMarkdown, '``$&``')
}

const replaceArgMessages = (args, str) => {
return _.reduce(args, (memo, value, index) => {
if (_.isString(value)) {
Expand Down Expand Up @@ -447,6 +452,7 @@ chai.use((chai, u) => {
const actual = chaiUtils.getActual(this, customArgs)

message = removeOrKeepSingleQuotesBetweenStars(message)
message = escapeMarkdown(message)

try {
assertProto.apply(this, args)
Expand Down