Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add escape sequence support for string literals (\t, \n, \r, etc.)#2331

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
Copilot wants to merge3 commits intodevelop
base:develop
Choose a base branch
Loading
fromcopilot/add-special-characters-support

Conversation

Copy link
Contributor

CopilotAI commentedDec 7, 2025
edited
Loading

Description

AlaSQL now processes standard escape sequences in string literals. Previously,\t,\n,\r, and similar sequences were treated as literal characters rather than their control character equivalents.

This implementation focuses on essential escape sequences while maintaining backward compatibility with existing quote escaping mechanisms.

Changes

  • Parser (src/alasqlparser.jison): ModifiedStringValue grammar rule to process escape sequences:\n,\t,\r,\\,\',\"
    • Uses specific regex/\\(n|t|r|\\|'|")/g to only match supported sequences
    • Removed support for\b,\f,\v to keep implementation conservative
    • Unsupported escape sequences are left as literal text (e.g.,\x remains as\x)
  • JSON compilation (src/58json.js): FixedJSONtoJS to escape strings properly when generating JavaScript code, preventing syntax errors with embedded quotes
  • Tests: Addedtest/test134-B.js with 8 test cases covering all supported escape sequences; updatedtest/test125.js to reflect new escape sequence behavior

Example

SELECT'hello\tworld'AS result;-- Returns: {result: 'helloworld'}SELECT'line1\nline2'AS result;-- Returns: {result: 'line1-- line2'}SELECT'back\\slash'AS result;-- Returns: {result: 'back\slash'}SELECT*FROM CSV('data.csv', {quote:"\""});-- Now correctly handles escaped quotes in parameters

Supported Escape Sequences

  • \n - newline
  • \t - tab
  • \r - carriage return
  • \\ - backslash
  • \' - single quote
  • \" - double quote

All other sequences (like\b,\f,\v,\x, etc.) are left as literal backslash + character.

Original prompt

This section details on the original issue you should resolve

<issue_title>Add \ t and similar characters to strings</issue_title>
<issue_description>Now AlaSQL does not support\t and other similar special characters.
</issue_description>

<agent_instructions>Name the test file test/test134-B.js</agent_instructions>

Comments on the Issue (you are@copilot in this section)

@mathiasrwHave added this to feature requests so people can vote http://feathub.com/agershun/alasql/+27

💬 We'd love your input! Share your thoughts on Copilot coding agent in our2 minute survey.

Co-authored-by: mathiasrw <1063454+mathiasrw@users.noreply.github.com>
CopilotAI changed the title[WIP] Add support for \t and similar special characters in stringsAdd escape sequence support for string literals (\t, \n, \r, etc.)Dec 7, 2025
CopilotAI requested a review frommathiasrwDecember 7, 2025 07:00
Copy link
Member

@mathiasrwmathiasrw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

please remove \b \f \v support

{$$=newyy.StringValue({value:$1.substr(1,$1.length-2).replace(/(\\\')/g,"'").replace(/(\'\')/g,"'")});}
{
var str=$1.substr(1,$1.length-2).replace(/(\'\')/g,"'");
str=str.replace(/\\(.)/g,function(match,char) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

You dont know if the first \ is escaped beforehand. You will need to find pairs like \ (regex as \\) or not pair (what you got now \(.))

Please see if you can place regex outside of the executing function

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Fixed the regex to be more specific:/\\(n|t|r|\\|'|")/g instead of/\\(.)/g. This only matches the supported escape sequences and properly handles\\ without needing to worry about pairs. (57cfff3)

case'b':return'\b';
case'f':return'\f';
case'v':return'\v';
case'\\':return'\\';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Please check if this is being solved via#2335

- Removed support for \b, \f, \v escape sequences as requested- Fixed regex to only match specific escape sequences: \n \t \r \\ \' \"- Removed default case that was accepting any character after backslash- Updated test134-B to remove tests for \b, \f, \v- Updated test125 escape sequence assertions to work with new behaviorCo-authored-by: mathiasrw <1063454+mathiasrw@users.noreply.github.com>
Copy link
ContributorAuthor

CopilotAI commentedDec 7, 2025

please remove \b \f \v support

Removed \b, \f, and \v support as requested. Now only supporting \n, \t, \r, \, ', and " escape sequences. (57cfff3)

functionJSONtoJS(obj,context,tableid,defcols){
vars='';
if(typeofobj=='string')s='"'+obj+'"';
if(typeofobj=='string')s='"'+escapeq(obj)+'"';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

@copilot

What is we have a string of data that contains \n, will it then get converted?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Yes, this is the correct behavior. When data contains actual newline characters (after SQL parsing converts\n to a newline),escapeq() converts them back to\n when generating JavaScript code. This ensures the generated JS code is syntactically valid.

Flow:

  1. SQL'hello\nworld' → Parser converts to actual newline → Stored in memory ashello<LF>world
  2. When generating JS code →escapeq() converts back to\n → Generated code:"hello\nworld"
  3. JS runtime executes → Results in newline character again

Withoutescapeq(), strings with newlines/quotes would produce invalid JavaScript syntax.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@mathiasrwmathiasrwAwaiting requested review from mathiasrw

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add \ t and similar characters to strings

2 participants

@mathiasrw

[8]ページ先頭

©2009-2025 Movatter.jp