Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]留言板欢迎信息中带图片的在Flask中访问会报错 #60

Open
Minuhy opened this issue Aug 24, 2022 · 2 comments
Open

[BUG]留言板欢迎信息中带图片的在Flask中访问会报错 #60

Minuhy opened this issue Aug 24, 2022 · 2 comments
Labels
bug Something isn't working todo

Comments

@Minuhy
Copy link

Minuhy commented Aug 24, 2022

Describe the bug
导出留言板欢迎信息中带图片的留言板信息后,使用displayer.py在本地访问留言板信息时直接报错:类型不正确,应该是str或类似bytes的类型

To Reproduce
在空间的留言板中编辑欢迎信息,添加一张图,然后导出,导出后使用displayer.py在本地访问留言板

Expected behavior
一堆报错,最终定位在template_filters.py的content_beautify函数,类型不正确,是由模板引擎调用引起的错误

Solution
目前避免这个报错使其能正常访问可以在template_filters.py的content_beautify函数的所有while之前加上类型判断

def content_beautify(s):
    '''恢复字符串中可能存在的表情、html 标签、css 样式等
    '''

    # TODO 出错,强行避免
    if isinstance(s, jinja2.runtime.Undefined):
        print("TODO:搜索的一个奇怪东西,可能有的内容显示不出来")
        print("s(type):", type(s), 's:', s)
        return s

    while True:
        # 恢复 @用户
        m = AT_PATTERN.search(s)
        if not m:
            break
        s = s.replace(m[0], '<a href="/%s">@%s</a>' % (m[1], m[2]))
........................................后面的代码都没有变...............

但是这样留言板的图片不会显示,显示的是一个image标签

@Minuhy Minuhy added the bug Something isn't working label Aug 24, 2022
@Minuhy
Copy link
Author

Minuhy commented Aug 24, 2022

留言板图片格式大概这样的:[img,300,200]http://a2.qpic.cn/psb?/V1rf=0-0[/img]
可以把 template_filters.py 中的 IMG_PATTERN 正则从 re.compile(r"\[img\](.*?)\[/img\]") 改为 re.compile(r"\[img.*\](.*?)\[/img\]") 这样可以正常显示图片,但是传入的s中使用print("s(type):", type(s), 's:', s)打印发现依然会有 s(type): <class 'jinja2.runtime.Undefined'> s: 这种类型,可能是模板引擎那边传过来的,模板引擎我不太懂,暂时只能通过判断规避这种类型

@wwwpf wwwpf added the todo label Aug 26, 2022
@wwwpf
Copy link
Owner

wwwpf commented Aug 26, 2022

收到,有空修复。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working todo
Projects
None yet
Development

No branches or pull requests

2 participants