Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

escape-sql-string

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

escape-sql-string

Simple SQL string escape.

  • 1.2.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3.7K
decreased by-18.32%
Maintainers
1
Weekly downloads
 
Created
Source

escape-sql-string Github Workflow Status

Simple SQL string escape.

import escapeString from 'escape-sql-string';

const sqlString = "Sup'er"
console.log(escapeString(sqlString)) // => Sup''er

Installation

npm install escape-sql-string

Note

Original implementation from sql-escape-string with the added typescript support

API

escapeString

Escapes the given string to protect against SQL injection attacks.

By default, it assumes that backslashes are not supported as they are not part of the standard SQL spec. Quoting from the SQLite website:

C-style escapes using the backslash character are not supported because they are not standard SQL.

This means three things:

  • backslashes and double quotes " are not escaped by default
  • single quotes are escaped via '' instead of \'
  • your sql engine should throw an error when encountering a backslash escape as part of a string, unless it is a literal backslash, i.e. 'backslash: \\'.

It is recommended to set the backslashSupported option true if your SQL engine supports it. In that case backslash sequences are escaped and single and double quotes are escaped via a backslash, i.e. '\''.

Parameters

  • value String the original string to be used in a SQL query
  • options Object opts
    • options.backslashSupported Boolean? if true backslashes are supported (optional, default false)
  • opts

Returns String the original string escaped wrapped in single quotes, i.e. 'mystring'

License

MIT

Keywords

FAQs

Package last updated on 12 Mar 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc