import { describe, it } from "mocha" import "should" import { fixModelHtmlEscaping, removeInvalidChars } from "./string" describe("fixModelHtmlEscaping", () => { it("should convert > to >", () => { fixModelHtmlEscaping("foo > bar").should.equal("foo > bar") }) it("should convert < to <", () => { fixModelHtmlEscaping("foo < bar").should.equal("foo < bar") }) it('should convert " to "', () => { fixModelHtmlEscaping("foo "bar"").should.equal('foo "bar"') }) it("should convert & to &", () => { fixModelHtmlEscaping("foo & bar").should.equal("foo & bar") }) it("should convert ' to '", () => { fixModelHtmlEscaping("foo 'bar'").should.equal("foo 'bar'") }) it("should handle multiple entities in the same string", () => { fixModelHtmlEscaping("<div>Hello "World" & 'Universe'</div>").should.equal( "
Hello \"World\" & 'Universe'
", ) }) it("should return unchanged string when no HTML entities are present", () => { fixModelHtmlEscaping("normal string").should.equal("normal string") }) }) describe("removeInvalidChars", () => { it("should remove replacement characters", () => { removeInvalidChars("hello\uFFFDworld").should.equal("helloworld") }) it("should remove � characters", () => { removeInvalidChars("hello�world").should.equal("helloworld") }) it("should remove multiple replacement characters", () => { removeInvalidChars("h\uFFFDe\uFFFDl\uFFFDl\uFFFDo").should.equal("hello") }) it("should remove multiple � characters", () => { removeInvalidChars("h�e�l�lo").should.equal("hello") }) it("should return unchanged string when no replacement characters are present", () => { removeInvalidChars("normal string").should.equal("normal string") }) })