From 3ac6aebae48615cc8f0e75cf820004e4d80c787d Mon Sep 17 00:00:00 2001 From: GordonZhang2024 Date: Tue, 30 Apr 2024 21:29:48 +0800 Subject: [PATCH] Add pytest files --- examples/example.ipynb | 46 ++++++++++++++++++++++++++++++++++++++++++ pyproject.toml | 2 +- test/test_escape.py | 10 +++++++++ 3 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 examples/example.ipynb create mode 100644 test/test_escape.py diff --git a/examples/example.ipynb b/examples/example.ipynb new file mode 100644 index 0000000..1c9c88a --- /dev/null +++ b/examples/example.ipynb @@ -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": [ + "&ltscript&gtalert(";Bad.";);&lt/script&gt\n" + ] + } + ], + "source": [ + "import xss_shield\n", + "unsafe_str = ''\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 +} diff --git a/pyproject.toml b/pyproject.toml index 0668d0e..2cf9102 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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" }, ] diff --git a/test/test_escape.py b/test/test_escape.py new file mode 100644 index 0000000..83d1176 --- /dev/null +++ b/test/test_escape.py @@ -0,0 +1,10 @@ +from xss_shield import * + + +class Test_escape: + def test_escape(self): + unsafe_str = '' + safe_str = escape(unsafe_str) + expected = '&ltscript&gtalert(";Bad.";);&lt/script&gt' + assert safe_str == expected +