U
    luf<  ã                   @   sˆ   d Z ddlZddlZddlmZmZ z$ddlmZ ddlZddl	Z	dZ
W n ek
r`   dZ
Y nX ejje
 ddG d	d
„ d
eƒƒZdS )a  This file contains test cases reported by third parties using
fuzzing tools, primarily from Google's oss-fuzz project. Some of these
represent real problems with Beautiful Soup, but many are problems in
libraries that Beautiful Soup depends on, and many of the test cases
represent different ways of triggering the same problem.

Grouping these test cases together makes it easy to see which test
cases represent the same problem, and puts the test cases in close
proximity to code that can trigger the problems.
é    N)ÚBeautifulSoupÚParserRejectedMarkup)ÚSelectorSyntaxErrorTFz/Prerequisites for fuzz tests are not installed.©Úreasonc                
   @   sä   e Zd ZdZdd„ Zej dddg¡dd„ ƒZej dd	d
ddg¡dd„ ƒZ	ej ddddg¡dd„ ƒZ
ej dddg¡dd„ ƒZejjddej dddddddg¡d d!„ ƒƒZejjddej dd"g¡d#d$„ ƒƒZd%d&„ Zd'S )(ÚTestFuzzz	.testcasec                 C   sò   |   |¡}ddddg}zt|d ƒt|ƒ }W n tk
rD   Y d S X |dd… |dd …  }}zt|dd … || d}W n* tk
r’   Y d S  tk
r¦   Y d S X t| d	¡ƒ z|j 	| 
d
d¡¡ W n tk
rä   Y d S X | ¡  d S )Nzlxml-xmlÚhtml5libúhtml.parserÚlxmlr   é   é
   )ÚfeaturesTzutf-8Úreplace)Ú_TestFuzz__markupÚintÚlenÚ
ValueErrorr   r   ÚlistZfind_allÚcssÚselectÚdecoder   Zprettify)ÚselfÚfilenameÚdataÚparsersÚidxZcss_selectorZsoup© r   ú7/tmp/pip-unpacked-wheel-pg4vfqbd/bs4/tests/test_fuzz.pyÚfuzz_test_with_css)   s&    
zTestFuzz.fuzz_test_with_cssr   z:clusterfuzz-testcase-minimized-bs4_fuzzer-5703933063462912z.crash-ffbdfa8a2b26f13537b68d3794b0478a4090ee4ac              	   C   s.   |   |¡}t t¡ t|dƒ W 5 Q R X d S ©Nr	   )r   ÚpytestZraisesr   r   ©r   r   Zmarkupr   r   r   Útest_rejected_markupD   s    
zTestFuzz.test_rejected_markupz:clusterfuzz-testcase-minimized-bs4_fuzzer-5984173902397440z:clusterfuzz-testcase-minimized-bs4_fuzzer-5167584867909632z:clusterfuzz-testcase-minimized-bs4_fuzzer-6124268085182464z:clusterfuzz-testcase-minimized-bs4_fuzzer-6450958476902400c                 C   s   |   |¡}t|dƒ ¡  d S r   )r   r   Úencoder!   r   r   r   Ú'test_deeply_nested_document_without_cssV   s    
z0TestFuzz.test_deeply_nested_document_without_cssz:clusterfuzz-testcase-minimized-bs4_fuzzer-5000587759190016z:clusterfuzz-testcase-minimized-bs4_fuzzer-5375146639360000z:clusterfuzz-testcase-minimized-bs4_fuzzer-5492400320282624c                 C   s   |   |¡ d S ©N©r   ©r   r   r   r   r   Útest_deeply_nested_documenti   s    z$TestFuzz.test_deeply_nested_documentz:clusterfuzz-testcase-minimized-bs4_fuzzer-4670634698080256z:clusterfuzz-testcase-minimized-bs4_fuzzer-5270998950477824c                 C   s   |   |¡ d S r%   r&   r'   r   r   r   Útest_soupsieve_errorss   s    zTestFuzz.test_soupsieve_errorszhtml5lib-specific problemsr   z:clusterfuzz-testcase-minimized-bs4_fuzzer-4818336571064320z:clusterfuzz-testcase-minimized-bs4_fuzzer-4999465949331456z:clusterfuzz-testcase-minimized-bs4_fuzzer-5843991618256896z:clusterfuzz-testcase-minimized-bs4_fuzzer-6241471367348224z:clusterfuzz-testcase-minimized-bs4_fuzzer-6600557255327744z.crash-0d306a50c8ed8bcd0785b67000fcd5dea1d33f08c                 C   s    |   |¡}tt|dƒ ¡ ƒ d S )Nr   )r   Úprintr   r#   r!   r   r   r   Ú&test_html5lib_parse_errors_without_cssƒ   s    
z/TestFuzz.test_html5lib_parse_errors_without_cssz:clusterfuzz-testcase-minimized-bs4_fuzzer-6306874195312640c                 C   s   |   |¡ d S r%   r&   r'   r   r   r   Útest_html5lib_parse_errors¡   s    z#TestFuzz.test_html5lib_parse_errorsc                 C   sD   |  | j¡s|| j7 }tj t¡d }tj |d|¡}t|dƒ ¡ S )Nr   ZfuzzÚrb)	ÚendswithÚTESTCASE_SUFFIXÚosÚpathÚsplitÚ__file__ÚjoinÚopenÚread)r   r   Zthis_dirr1   r   r   r   Z__markup«   s
    
zTestFuzz.__markupN)Ú__name__Ú
__module__Ú__qualname__r/   r   r    ÚmarkZparametrizer"   r$   r(   r)   Úskipr+   r,   r   r   r   r   r   r      sj   
þÿ
üÿ
ýÿ
þÿ

ïÿþÿr   )Ú__doc__r0   r    Zbs4r   r   Zsoupsieve.utilr   r
   r   Zfully_fuzzableÚImportErrorr:   ZskipifÚobjectr   r   r   r   r   Ú<module>   s   

