Skip to content

Commit

Permalink
Add pytest files
Browse files Browse the repository at this point in the history
  • Loading branch information
GordonZhang2024 committed Apr 30, 2024
1 parent 77431db commit 3ac6aeb
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
46 changes: 46 additions & 0 deletions examples/example.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"id": "5f41eab9-0fc3-43eb-add1-18f9ad56dc14",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"&ampltscript&ampgtalert(&#34&#59Bad.&#34&#59)&#59&amplt/script&ampgt\n"
]
}
],
"source": [
"import xss_shield\n",
"unsafe_str = '<script>alert(\"Bad.\");</script>'\n",
"safe_str = xss_shield.escape(unsafe_str)\n",
"print(safe_str)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.2"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "hatchling.build"

[project]
name = "xss-shield"
version = "0.0.2"
version = "0.0.3"
authors = [
{ name="Gordon Zhang", email="jp20171211@163.com" },
]
Expand Down
10 changes: 10 additions & 0 deletions test/test_escape.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from xss_shield import *


class Test_escape:
def test_escape(self):
unsafe_str = '<script>alert("Bad.");</script>'
safe_str = escape(unsafe_str)
expected = '&ampltscript&ampgtalert(&#34&#59Bad.&#34&#59)&#59&amplt/script&ampgt'
assert safe_str == expected

0 comments on commit 3ac6aeb

Please sign in to comment.