Skip to content

Commit d97d48a

Browse files
Fix Issue316 - set sandbox to be false by default (#322)
1 parent 2436fea commit d97d48a

File tree

6 files changed

+42
-14
lines changed

6 files changed

+42
-14
lines changed

pypandoc/__init__.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555

5656
def convert_text(source:str, to:str, format:str, extra_args:Iterable=(), encoding:str='utf-8',
5757
outputfile:Union[None, str, Path]=None, filters:Union[Iterable, None]=None, verify_format:bool=True,
58-
sandbox:bool=True, cworkdir:Union[str, None]=None) -> str:
58+
sandbox:bool=False, cworkdir:Union[str, None]=None) -> str:
5959
"""Converts given `source` from `format` to `to`.
6060
6161
:param str source: Unicode string or bytes (see encoding)
@@ -80,7 +80,7 @@ def convert_text(source:str, to:str, format:str, extra_args:Iterable=(), encodin
8080
(Default value = True)
8181
8282
:param bool sandbox: Run pandoc in pandocs own sandbox mode, limiting IO operations in readers and writers to reading the files specified on the command line. Anyone using pandoc on untrusted user input should use this option. Note: This only does something, on pandoc >= 2.15
83-
(Default value = True)
83+
(Default value = False)
8484
8585
:returns: converted string (unicode) or an empty string if an outputfile was given
8686
:rtype: unicode
@@ -98,7 +98,7 @@ def convert_text(source:str, to:str, format:str, extra_args:Iterable=(), encodin
9898

9999
def convert_file(source_file:Union[list, str, Path, Generator], to:str, format:Union[str, None]=None,
100100
extra_args:Iterable=(), encoding:str='utf-8', outputfile:Union[None, str, Path]=None,
101-
filters:Union[Iterable, None]=None, verify_format:bool=True, sandbox:bool=True,
101+
filters:Union[Iterable, None]=None, verify_format:bool=True, sandbox:bool=False,
102102
cworkdir:Union[str, None]=None) -> str:
103103
"""Converts given `source` from `format` to `to`.
104104
@@ -130,7 +130,7 @@ def convert_file(source_file:Union[list, str, Path, Generator], to:str, format:U
130130
(Default value = True)
131131
132132
:param bool sandbox: Run pandoc in pandocs own sandbox mode, limiting IO operations in readers and writers to reading the files specified on the command line. Anyone using pandoc on untrusted user input should use this option. Note: This only does something, on pandoc >= 2.15
133-
(Default value = True)
133+
(Default value = False)
134134
135135
:returns: converted string (unicode) or an empty string if an outputfile was given
136136
:rtype: unicode
@@ -318,7 +318,7 @@ def _validate_formats(format, to, outputfile):
318318

319319
def _convert_input(source, format, input_type, to, extra_args=(),
320320
outputfile=None, filters=None, verify_format=True,
321-
sandbox=True, cworkdir=None):
321+
sandbox=False, cworkdir=None):
322322

323323
_check_log_handler()
324324
_ensure_pandoc_path()

setup_binary.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def finalize_options(self):
3535
def run(self):
3636
from pypandoc.pandoc_download import download_pandoc
3737
targetfolder = os.path.join(os.path.dirname(os.path.realpath(__file__)), "pypandoc", "files")
38-
download_pandoc(targetfolder=targetfolder)
38+
download_pandoc(targetfolder=targetfolder, version="2.19.2")
3939

4040

4141
cmd_classes = {'download_pandoc': DownloadPandocCommand}

test_data/index.html

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<title>Test Title</title>
6+
<meta name="viewport" content="width=device-width, initial-scale=1">
7+
8+
<body>
9+
10+
<h1 class="section">Test Heading</h1>
11+
12+
<div class="row">
13+
<img src="test.png" alt="test alt" />
14+
</div>
15+
16+
</body>
17+
18+
</html>

test_data/test.docx

9.69 KB
Binary file not shown.

test_data/test.png

20.3 KB
Loading

tests.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,21 @@ def test_basic_conversion_from_http_url(self):
232232
received = pypandoc.convert_file(url, 'html')
233233
assert "GPL2 license" in received
234234

235+
def test_conversion_with_data_files(self):
236+
# remove our test.docx file from our test_data dir if it already exosts
237+
test_data_dir = os.path.join(os.path.dirname(__file__), 'test_data')
238+
test_docx_file = os.path.join(test_data_dir, 'test.docx')
239+
if os.path.exists(test_docx_file):
240+
os.remove(test_docx_file)
241+
result = pypandoc.convert_file(
242+
os.path.join(test_data_dir, 'index.html'),
243+
to='docx',
244+
format='html',
245+
outputfile=test_docx_file,
246+
sandbox=True,
247+
)
248+
print(result)
249+
235250
def test_convert_with_custom_writer(self):
236251
lua_file_content = self.create_sample_lua()
237252
with closed_tempfile('.md', text='# title\n') as file_name:
@@ -452,14 +467,9 @@ def test_conversion_stderr(self):
452467
output = re.sub(r'\r', '', output)
453468
output = output.replace("'missing.png'",
454469
"missing.png")
455-
expected = (u'[WARNING] Could not fetch resource '
456-
u'missing.png: PandocResourceNotFound '
457-
u'"missing.png"\n'
458-
u'[WARNING] Could not fetch resource '
459-
u'missing.png: PandocResourceNotFound '
460-
u'"missing.png"\n\n')
461-
self.assertEqual(expected, output)
462-
470+
output = output.lower()
471+
print(output)
472+
assert "[warning] could not fetch resource missing.png" in output
463473

464474
def test_conversion_stderr_nullhandler(self):
465475

0 commit comments

Comments
 (0)