slim-embedded-minify 0.2.5 → 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 14375e81992194bca2bc3c42733011ccb783db89cf89a3dffbb62ec3245f2184
4
- data.tar.gz: 824370e31b97a05335c8d4c4a64c1bed55ea02ea9a678faa8609a4308c1657b6
3
+ metadata.gz: a0acd763c9c3c2869fee898e2da36f1a26aa1aa2430d9cfe9c3008db35ecd442
4
+ data.tar.gz: b3d30f07bbf45aa062deac825d4e849958f495fc4cae6cb819362ebb32f8c53b
5
5
  SHA512:
6
- metadata.gz: 947549a68e10777ab21e2779ac67491a7be49cdb54e800f08e8b0fa891138ee72dc249f3216bbe9ac8f2b9f1e3574f1592a156c2ef90fa3c751771b1237e317b
7
- data.tar.gz: df9d4962e7ba6e74492306c5367ff7c44bb6c5a9527b77dd19514bd2104da0a0de0020cd0bac68e58ccdbe33de7cfe48bb3819eef2cb4c4fb2391a38540e69e4
6
+ metadata.gz: f7e085fd30ce3b514709e55e8999c919e2ab4f25fbdcc7c3b62617a8ee09e890d732af7d6c03064eda833b002fbc5b2cec9cccf3ef5afe7ab93a7c843b708ad5
7
+ data.tar.gz: 26466135a7c571e04eb572f49906f8f17d3ccc21ae1be8ca44e9a00c1da1ae591cb7583d16cbada24d34e0f324a7bf1dd32afc7b4248ac82afed387527fffd58
data/CHANGELOG.md CHANGED
@@ -1,8 +1,12 @@
1
1
  ## Unreleased
2
2
 
3
+ ## 0.2.6 - 2023-08-01
4
+
5
+ - Fix incorrect removing when using escaped quotation.
6
+
3
7
  ## 0.2.5 - 2023-07-27
4
8
 
5
- Fix to not delete anything other than comments.
9
+ - Fix to not delete anything other than comments.
6
10
 
7
11
  ## 0.2.4 - 2023-07-27
8
12
 
@@ -14,6 +14,8 @@ module Slim
14
14
  def remove_comments!(line)
15
15
  need_deletion = false
16
16
  need_deletion_all = false
17
+ escaped = false
18
+ escaped_backslash = false
17
19
  inside_char = nil
18
20
  line[-1] = line.last.chars.each_with_index.map do |char, index|
19
21
  next if need_deletion_all
@@ -29,22 +31,25 @@ module Slim
29
31
  elsif char == "/" && next_char(line, index) == "/" && inside_char.nil? && !need_deletion
30
32
  need_deletion_all = true
31
33
  next
32
- elsif char == '"' && !need_deletion
33
- if inside_char == '"'
34
- inside_char = nil
35
- next char
34
+ elsif char == "\\" && next_char(line, index) == "\\" && inside_char
35
+ escaped_backslash = true
36
+ next char
37
+ elsif char == "\\"
38
+ if ["'", '"'].include?(next_char(line, index)) && inside_char == next_char(line, index) && !escaped_backslash
39
+ escaped = true
36
40
  end
37
-
38
- inside_char = '"' if inside_char.nil?
39
- elsif char == "'" && !need_deletion
40
- if inside_char == "'"
41
- inside_char = nil
41
+ escaped_backslash = false
42
+ next char
43
+ elsif ["'", '"'].include?(char) && !need_deletion
44
+ if inside_char == char
45
+ inside_char = nil unless escaped
46
+ escaped = false
42
47
  next char
43
48
  end
44
49
 
45
- inside_char = "'" if inside_char.nil?
50
+ inside_char = char if inside_char.nil?
46
51
  end
47
- char unless need_deletion
52
+ char if !need_deletion || inside_char
48
53
  end&.compact&.join
49
54
  end
50
55
  end
@@ -75,7 +75,7 @@ module Slim
75
75
  end
76
76
 
77
77
  def prev_char(line, index)
78
- line.last[index - 1]
78
+ line.last[index - 1] if index.positive?
79
79
  end
80
80
 
81
81
  def next_char(line, index)
@@ -89,7 +89,33 @@ module Slim
89
89
  end
90
90
 
91
91
  def stripped_quotes(line)
92
- line.last.gsub(/(['"]).*?\1/, "")
92
+ inside_char = nil
93
+ escaped = false
94
+ escaped_backslash = false
95
+ line.last.chars.each_with_index.filter_map do |char, index|
96
+ if ["'", '"'].include?(char) && inside_char.nil?
97
+ inside_char = char
98
+ next
99
+ elsif char == "\\" && next_char(line, index) == "\\" && inside_char
100
+ escaped_backslash = true
101
+ next
102
+ elsif char == "\\"
103
+ if ["'",
104
+ '"'].include?(next_char(line, index)) && inside_char == next_char(line, index) && !escaped_backslash
105
+ escaped = true
106
+ end
107
+ escaped_backslash = false
108
+ next
109
+ elsif char == inside_char && !inside_char.nil?
110
+ inside_char = nil unless escaped
111
+ escaped = false
112
+ next
113
+ elsif inside_char
114
+ next
115
+ else
116
+ char
117
+ end
118
+ end.join
93
119
  end
94
120
 
95
121
  def empty_line?(line)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SlimEmbeddedMinify
4
- VERSION = "0.2.5"
4
+ VERSION = "0.2.6"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slim-embedded-minify
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yudai Takada
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-07-27 00:00:00.000000000 Z
11
+ date: 2023-08-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: slim