taozhi8833998 / node-sql-parser

Parse simple SQL statements into an abstract syntax tree (AST) with the visited tableList and convert it back to SQL
https://taozhi8833998.github.io/node-sql-parser/
Apache License 2.0
803 stars 180 forks source link

Request for help. My product manager has requested to preserve line breaks in SQL expressions, but the content I obtained through parser.sqlify no longer contains any line breaks. #1689

Open jxh150535011 opened 10 months ago

jxh150535011 commented 10 months ago

Original requirement: The product manager wants users to input custom expressions, and the frontend performs formatting validation, field validation, and provides shortcuts for syntax input. I have successfully addressed these requirements using this library. For example, when performing field validation, I return the fields in the form of [xx] and later dynamically replace these [xx] with <span title="xx does not exist">xx</span> using regular expressions. Of course, I have taken into account the risk of HTML injection.

Now the problem is, when users input line breaks, for example, some users may input very long expressions and expect to preserve some basic formatting. However, when using sqlify, the line breaks and content indentation are lost. Can you please advise on how to proceed?"

jxh150535011 commented 10 months ago

原始需求: 产品经理希望让用户输入自定义表达式,前端进行格式校验、字段校验、快捷的语法输入,这些我用这个库都很好的解决了。例如字段校验的时候,我是将字段返回成[xx] 的形式,在后续通过正则来动态替换这些[xx] => <span title="xx does not exist">xx</span>,当然我已经有效的考虑了html注入的风险。` 现在问题是,当用户输入换行符,例如 有些用户在输入表达式的时候可能非常的长,所以期望保留一些基本的格式,这个时候进行 sqlify ,这个换行 或内容缩进就都没了,请问我该怎么办 ”

cchepelov commented 7 months ago

https://github.com/cchepelov/node-sql-parser/pull/1