为什么python双引号在文件名中转换为连字符?

nim*_*smi 5 python string django reportlab

我正在使用 Django 中的 ReportLab 生成一些 pdf。我遵循并试验了这个问题的答案,并意识到其中的双引号没有意义:

response['Content-Disposition'] = 'inline; filename=constant_"%s_%s".pdf'\
% ('foo','bar')
Run Code Online (Sandbox Code Playgroud)

给出文件名 constant_-foo_bar-.pdf

response['Content-Disposition'] = 'inline; filename=constant_%s_%s.pdf' \
% ('foo','bar')
Run Code Online (Sandbox Code Playgroud)

给出文件名 constant_foo_bar.pdf

为什么是这样?它只是与文件系统的 slug-esque 消毒有关吗?

sup*_*cuo 2

从这个问题的研究看来,实际上是浏览器在进行编码/转义。我曾经cURL确认过 Django 本身不会转义这些标头。首先,我设置了一个最小的测试视图:

# views.py 
def index(request):
    response = render(request, 'template.html')
    response['Content-Disposition'] = 'inline; filename=constant"a_b".html'
    return response
Run Code Online (Sandbox Code Playgroud)

然后跑:

# views.py 
def index(request):
    response = render(request, 'template.html')
    response['Content-Disposition'] = 'inline; filename=constant"a_b".html'
    return response
Run Code Online (Sandbox Code Playgroud)

查看标题:filename=constant"a_b".html。引用仍然存在!