|
| 1 | +# spec/lib/discourse_ai/utils/diff_utils/safety_checker_spec.rb |
| 2 | + |
| 3 | +require "rails_helper" |
| 4 | + |
| 5 | +RSpec.describe DiscourseAi::Utils::DiffUtils::SafetyChecker do |
| 6 | + describe "#safe?" do |
| 7 | + subject { described_class.new(text).safe? } |
| 8 | + |
| 9 | + context "with safe text" do |
| 10 | + let(:text) { "This is a simple safe text without issues." } |
| 11 | + |
| 12 | + it { is_expected.to eq(true) } |
| 13 | + |
| 14 | + context "with normal HTML tags" do |
| 15 | + let(:text) { "Here is <strong>bold</strong> and <em>italic</em> text." } |
| 16 | + it { is_expected.to eq(true) } |
| 17 | + end |
| 18 | + |
| 19 | + context "with balanced markdown and no partial emoji" do |
| 20 | + let(:text) { "This is **bold**, *italic*, and a smiley :smile:!" } |
| 21 | + it { is_expected.to eq(true) } |
| 22 | + end |
| 23 | + |
| 24 | + context "with balanced quote blocks" do |
| 25 | + let(:text) { "[quote]Quoted text[/quote]" } |
| 26 | + it { is_expected.to eq(true) } |
| 27 | + end |
| 28 | + |
| 29 | + context "with complete image markdown" do |
| 30 | + let(:text) { "" } |
| 31 | + it { is_expected.to eq(true) } |
| 32 | + end |
| 33 | + end |
| 34 | + |
| 35 | + context "with unsafe text" do |
| 36 | + context "with unclosed markdown link" do |
| 37 | + let(:text) { "This is a [link(https://example.com)" } |
| 38 | + it { is_expected.to eq(false) } |
| 39 | + end |
| 40 | + |
| 41 | + context "with unclosed raw HTML tag" do |
| 42 | + let(:text) { "Text with <div unclosed tag" } |
| 43 | + it { is_expected.to eq(false) } |
| 44 | + end |
| 45 | + |
| 46 | + context "with trailing incomplete URL" do |
| 47 | + let(:text) { "Check this out https://example.com/something" } # no closing punctuation |
| 48 | + it { is_expected.to eq(false) } |
| 49 | + end |
| 50 | + |
| 51 | + context "with unclosed backticks" do |
| 52 | + let(:text) { "Here is some `inline code without closing" } |
| 53 | + it { is_expected.to eq(false) } |
| 54 | + end |
| 55 | + |
| 56 | + context "with unbalanced bold or italic markdown" do |
| 57 | + let(:text) { "This is *italic without closing" } |
| 58 | + it { is_expected.to eq(false) } |
| 59 | + end |
| 60 | + |
| 61 | + context "with incomplete image markdown" do |
| 62 | + let(:text) { "Image  |
| 63 | + it { is_expected.to eq(false) } |
| 64 | + end |
| 65 | + |
| 66 | + context "with unbalanced quote blocks" do |
| 67 | + let(:text) { "[quote]Unclosed quote block" } |
| 68 | + it { is_expected.to eq(false) } |
| 69 | + end |
| 70 | + |
| 71 | + context "with unclosed triple backticks" do |
| 72 | + let(:text) { "```code block without closing" } |
| 73 | + it { is_expected.to eq(false) } |
| 74 | + end |
| 75 | + |
| 76 | + # context "with partial emoji" do |
| 77 | + # let(:text) { "A partial emoji :smile" } |
| 78 | + # it { is_expected.to eq(false) } |
| 79 | + # end |
| 80 | + end |
| 81 | + end |
| 82 | +end |
0 commit comments