Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ force styles, we will always use the quote type specified.
- Fixed LastStmt (return/break etc.) still being formatted when it wasn't defined inside the range
- Fixed hanging expressions which are inside function calls being indented unnecessarily by one extra level
- Fixed parentheses being incorrectly removed around a function definition, which may be called like `(function() ... end)()`
- Fixed some string escapes being incorrectly deemed as unnecessary

## [0.5.0] - 2021-02-24
### Added
Expand Down
2 changes: 1 addition & 1 deletion src/formatters/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ impl CodeFormatter {
// Based off https://github.com/prettier/prettier/blob/181a325c1c07f1a4f3738665b7b28288dfb960bc/src/common/util.js#L439
lazy_static::lazy_static! {
static ref RE: regex::Regex = regex::Regex::new(r#"\\?(["'])|\\([\S\s])"#).unwrap();
static ref UNNECESSARY_ESCAPES: regex::Regex = regex::Regex::new(r#"^[^\n\r"'0-7\\bfnrt-vx\u2028\u2029]$"#).unwrap();
static ref UNNECESSARY_ESCAPES: regex::Regex = regex::Regex::new(r#"^[^\n\r"'0-7\\abfnrtuvxz]$"#).unwrap();
}
let quote_to_use = self.get_quote_to_use(literal);
let literal = RE
Expand Down
17 changes: 17 additions & 0 deletions tests/inputs/string-escapes-2.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
-- standard escapes
local a = "foo \a \b \f \n \r \t \v \\ \" \'"

-- decimal escapes
local b = "\000 \001 \189 \254 \255"

-- lua 5.2: hex escapes
local c = "hello \x77\x6f\x72\x6c\x64\x99"

-- lua 5.2: \z
local d = "hello \z test"

-- lua 5.3: utf8
local e = "\u{123} \u{255}"

-- wrong:
local f = "\q \p \e"
23 changes: 23 additions & 0 deletions tests/snapshots/tests__standard@string-escapes-2.lua.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
source: tests/tests.rs
expression: format(&contents)

---
-- standard escapes
local a = "foo \a \b \f \n \r \t \v \\ \" '"

-- decimal escapes
local b = "\000 \001 \189 \254 \255"

-- lua 5.2: hex escapes
local c = "hello \x77\x6f\x72\x6c\x64\x99"

-- lua 5.2: \z
local d = "hello \z test"

-- lua 5.3: utf8
local e = "\u{123} \u{255}"

-- wrong:
local f = "q p e"