-
Notifications
You must be signed in to change notification settings - Fork 0
bugfix: Fixed an error that occurred when undefined was entered in unescapeHtml and escapeHtml #44
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
75e70ac
bugfix: Fixed an error that occurred when undefined was entered in un…
klmhyeonwoo 3673f6c
Update package/stringUtil/escapeHtml/index.ts
klmhyeonwoo f4a302d
Update package/stringUtil/unescapeHtml/index.test.ts
klmhyeonwoo 014ab1c
Update package/stringUtil/unescapeHtml/index.ts
klmhyeonwoo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,3 +21,5 @@ dist | |
| *.njsproj | ||
| *.sln | ||
| *.sw? | ||
|
|
||
| vitest-report.xml | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,37 @@ | ||
| import { expect, test } from "vitest"; | ||
| import { describe, expect, test } from "vitest"; | ||
| import escapeHtml from "."; | ||
|
|
||
| test("HTML 특수 문자를 이스케이프한다.", () => { | ||
| const input = "<span> 안녕하세요 </span>"; | ||
| const output = escapeHtml(input); | ||
| expect(output).toBe("<span> 안녕하세요 </span>"); | ||
| describe("escapeHtml 유틸 함수 테스트", () => { | ||
| test("HTML 특수 문자를 올바르게 이스케이프한다", () => { | ||
| const input = "<span> 안녕하세요 </span>"; | ||
| const output = escapeHtml(input); | ||
| expect(output).toBe("<span> 안녕하세요 </span>"); | ||
| }); | ||
|
|
||
| test("여러 HTML 특수 문자를 포함한 문자열을 올바르게 이스케이프한다", () => { | ||
| const input = "Tom & Jerry <3 \"Best Friends\" 'Forever' / Fun"; | ||
| const output = escapeHtml(input); | ||
| expect(output).toBe( | ||
| "Tom & Jerry <3 "Best Friends" 'Forever' / Fun" | ||
| ); | ||
| }); | ||
|
|
||
| test("HTML 특수 문자가 없는 문자열은 그대로 반환한다", () => { | ||
| const input = "Hello World!"; | ||
| const output = escapeHtml(input); | ||
| expect(output).toBe("Hello World!"); | ||
| }); | ||
|
|
||
| test("빈 문자열을 입력하면 빈 문자열을 반환한다", () => { | ||
| const input = ""; | ||
| const output = escapeHtml(input); | ||
| expect(output).toBe(""); | ||
| }); | ||
|
|
||
| test("null 또는 undefined를 입력하면 그대로 반환한다", () => { | ||
| // @ts-ignore | ||
| expect(escapeHtml(null)).toBe(null); | ||
| // @ts-ignore | ||
| expect(escapeHtml(undefined)).toBe(undefined); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,36 @@ | ||
| import { expect, test } from "vitest"; | ||
| import { describe, expect, test } from "vitest"; | ||
| import unescapeHtml from "."; | ||
|
|
||
| test("HTML 특수 문자를 언이스케이프한다.", () => { | ||
| const input = "<span> 안녕하세요 </span>"; | ||
| const output = unescapeHtml(input); | ||
| expect(output).toBe("<span> 안녕하세요 </span>"); | ||
| }); | ||
|
|
||
| describe("unsecapeHtml 유틸 함수 테스트", () => { | ||
klmhyeonwoo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| test("여러 HTML 특수 문자를 포함한 문자열을 올바르게 언이스케이프한다", () => { | ||
| const input = | ||
| "Tom & Jerry <3 "Best Friends" 'Forever' / Fun"; | ||
| const output = unescapeHtml(input); | ||
| expect(output).toBe("Tom & Jerry <3 \"Best Friends\" 'Forever' / Fun"); | ||
| }); | ||
|
|
||
| test("HTML 특수 문자가 없는 문자열은 그대로 반환한다", () => { | ||
| const input = "Hello World!"; | ||
| const output = unescapeHtml(input); | ||
| expect(output).toBe("Hello World!"); | ||
| }); | ||
|
|
||
| test("빈 문자열을 입력하면 빈 문자열을 반환한다", () => { | ||
| const input = ""; | ||
| const output = unescapeHtml(input); | ||
| expect(output).toBe(""); | ||
| }); | ||
|
|
||
| test("null 또는 undefined를 입력하면 그대로 반환한다", () => { | ||
| // @ts-ignore | ||
| expect(unescapeHtml(null)).toBe(null); | ||
| // @ts-ignore | ||
| expect(unescapeHtml(undefined)).toBe(undefined); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,10 @@ | ||
| export default function unescapeHtml(str: string): string { | ||
klmhyeonwoo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return str.replace(/&/g, "&") | ||
| .replace(/</g, "<") | ||
| .replace(/>/g, ">") | ||
| .replace(/"/g, "\"") | ||
| .replace(/'/g, "'") | ||
| .replace(///g, "/"); | ||
| } | ||
| if (str == null) return str; | ||
| return str | ||
| .replace(/&/g, "&") | ||
| .replace(/</g, "<") | ||
| .replace(/>/g, ">") | ||
| .replace(/"/g, '"') | ||
| .replace(/'/g, "'") | ||
| .replace(///g, "/"); | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.