summaryrefslogtreecommitdiff
path: root/spec/features/markdown/math_spec.rb
blob: 68d99b4241af3ef2923f951e7d5d3cbf503359a4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# frozen_string_literal: true

require 'spec_helper'

describe 'Math rendering', :js do
  let!(:project) { create(:project, :public) }

  it 'renders inline and display math correctly' do
    description = <<~MATH
      This math is inline $`a^2+b^2=c^2`$.

      This is on a separate line
      ```math
      a^2+b^2=c^2
      ```
    MATH

    issue = create(:issue, project: project, description: description)

    visit project_issue_path(project, issue)

    expect(page).to have_selector('.katex .mord.mathdefault', text: 'b')
    expect(page).to have_selector('.katex-display .mord.mathdefault', text: 'b')
  end

  it 'only renders non XSS links' do
    description = <<~MATH
      This link is valid $`\\href{javascript:alert('xss');}{xss}`$.

      This link is valid $`\\href{https://gitlab.com}{Gitlab}`$.
    MATH

    issue = create(:issue, project: project, description: description)

    visit project_issue_path(project, issue)

    expect(page).to have_selector('.katex-error', text: "\href{javascript:alert('xss');}{xss}")
    expect(page).to have_selector('.katex-html a', text: 'Gitlab')
  end
end