Skip to content

Commit

Permalink
fix: do not allow image markdown in assertions and command log (#17777)
Browse files Browse the repository at this point in the history
  • Loading branch information
sainthkh authored Aug 19, 2021
1 parent 07127f9 commit 6eed2e6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
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

4 comments on commit 6eed2e6

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 6eed2e6 Aug 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the linux x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/8.3.1/circle-develop-6eed2e667b1535b238d653513e5960fb2cea454d/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 6eed2e6 Aug 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AppVeyor has built the win32 ia32 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/8.3.1/appveyor-develop-6eed2e667b1535b238d653513e5960fb2cea454d/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 6eed2e6 Aug 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AppVeyor has built the win32 x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/8.3.1/appveyor-develop-6eed2e667b1535b238d653513e5960fb2cea454d/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 6eed2e6 Aug 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the darwin x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/8.3.1/circle-develop-6eed2e667b1535b238d653513e5960fb2cea454d/cypress.tgz

Please sign in to comment.