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]: 评论未填邮件地址时,会报错 || [Bug]: When commenting without filling in the email address, an error will be reported #2502

Closed
pygyme opened this issue May 12, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@pygyme
Copy link
Contributor

pygyme commented May 12, 2024

问题描述 | Describe the bug

报错信息如下:

May 11 23:49:35 admired-nodes-1.localdomain node[160164]: TypeError: Cannot read property 'toLowerCase' of undefined
May 11 23:49:35 admired-nodes-1.localdomain node[160164]:     at module.exports.run (/root/waline/node_modules/@waline/vercel/src/service/notify.js:88:67)
May 11 23:49:35 admired-nodes-1.localdomain node[160164]:     at module.exports.postAction (/root/waline/node_modules/@waline/vercel/src/controller/comment.js:203:20)
May 11 23:49:35 admired-nodes-1.localdomain node[160164]:     at cors (/root/waline/node_modules/@koa/cors/index.js:110:16)

导致报错的问题代码:

? comment.mail.toLowerCase() === AUTHOR.toLowerCase()

490-497行, 未处理mail字段为空的情况。 客户端不强制登录的时候,评论里面是允许可以不填邮件地址的,从而导致报错。

推荐解决方案:

后端API接收到评论请求数据时, 对字段进行校验检查, 对于 undefined 的字段, 给定一个默认值。

问题网站 | Website URL

https://hello.com

服务部署在哪里? | Where your waline deploy?

Self Host

数据存储在哪里?| Where your comment data store?

SQLite


Problem description | Describe the bug

The error message is as follows:

May 11 23:49:35 admired-nodes-1.localdomain node[160164]: TypeError: Cannot read property 'toLowerCase' of undefined
May 11 23:49:35 admired-nodes-1.localdomain node[160164]: at module.exports.run (/root/waline/node_modules/@waline/vercel/src/service/notify.js:88:67)
May 11 23:49:35 admired-nodes-1.localdomain node[160164]: at module.exports.postAction (/root/waline/node_modules/@waline/vercel/src/controller/comment.js:203:20)
May 11 23:49:35 admired-nodes-1.localdomain node[160164]: at cors (/root/waline/node_modules/@koa/cors/index.js:110:16)

The problem code that caused the error:

? comment.mail.toLowerCase() === AUTHOR.toLowerCase()

Lines 490-497 do not handle the situation where the mail field is empty. When the client is not forced to log in, it is allowed not to fill in the email address in the comments, resulting in an error.

Recommended solution:

When the backend API receives the comment request data, it performs verification checks on the fields and gives a default value to undefined fields.

Question Website | Website URL

https://hello.com

Where is the service deployed? | Where your waline deploy?

Self Host

Where is the data stored? | Where your comment data store?

SQLite

@pygyme pygyme added the bug Something isn't working label May 12, 2024
@github-actions github-actions bot changed the title [Bug]: 评论未填邮件地址时,会报错 [Bug]: 评论未填邮件地址时,会报错 || [Bug]: When commenting without filling in the email address, an error will be reported May 12, 2024
@lizheming
Copy link
Collaborator

lizheming commented May 12, 2024

点赞,谢谢反馈。看你已经找到地方了,如果有空的话欢迎提个 PR 帮忙修复下呀,谢谢~


Like, thanks for the feedback. It seems that you have found the place. If you are free, you are welcome to submit a PR to help fix it. Thank you~

pygyme added a commit to pygyme/waline that referenced this issue May 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants