erb 5.0.2 → 5.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -39,29 +39,44 @@ static VALUE
39
39
  optimized_escape_html(VALUE str)
40
40
  {
41
41
  VALUE vbuf;
42
- char *buf = ALLOCV_N(char, vbuf, escaped_length(str));
42
+ char *buf = NULL;
43
43
  const char *cstr = RSTRING_PTR(str);
44
44
  const char *end = cstr + RSTRING_LEN(str);
45
45
 
46
- char *dest = buf;
46
+ const char *segment_start = cstr;
47
+ char *dest = NULL;
47
48
  while (cstr < end) {
48
49
  const unsigned char c = *cstr++;
49
50
  uint8_t len = html_escape_table[c].len;
50
51
  if (len) {
52
+ size_t segment_len = cstr - segment_start - 1;
53
+ if (!buf) {
54
+ buf = ALLOCV_N(char, vbuf, escaped_length(str));
55
+ dest = buf;
56
+ }
57
+ if (segment_len) {
58
+ memcpy(dest, segment_start, segment_len);
59
+ dest += segment_len;
60
+ }
61
+ segment_start = cstr;
51
62
  memcpy(dest, html_escape_table[c].str, len);
52
63
  dest += len;
53
64
  }
54
- else {
55
- *dest++ = c;
65
+ }
66
+ if (buf) {
67
+ size_t segment_len = cstr - segment_start;
68
+ if (segment_len) {
69
+ memcpy(dest, segment_start, segment_len);
70
+ dest += segment_len;
56
71
  }
57
72
  }
58
73
 
59
74
  VALUE escaped = str;
60
- if (RSTRING_LEN(str) < (dest - buf)) {
75
+ if (buf) {
61
76
  escaped = rb_str_new(buf, dest - buf);
62
77
  preserve_original_state(str, escaped);
78
+ ALLOCV_END(vbuf);
63
79
  }
64
- ALLOCV_END(vbuf);
65
80
  return escaped;
66
81
  }
67
82
 
data/lib/erb/util.rb CHANGED
@@ -47,19 +47,19 @@ module ERB::Util
47
47
  alias h html_escape
48
48
  module_function :h
49
49
 
50
- #
51
- # A utility method for encoding the String _s_ as a URL.
52
- #
53
- # require "erb"
54
- # include ERB::Util
55
- #
56
- # puts url_encode("Programming Ruby: The Pragmatic Programmer's Guide")
57
- #
58
- # _Generates_
59
- #
60
- # Programming%20Ruby%3A%20%20The%20Pragmatic%20Programmer%27s%20Guide
61
- #
62
50
  if CGI.respond_to?(:escapeURIComponent)
51
+ #
52
+ # A utility method for encoding the String _s_ as a URL.
53
+ #
54
+ # require "erb"
55
+ # include ERB::Util
56
+ #
57
+ # puts url_encode("Programming Ruby: The Pragmatic Programmer's Guide")
58
+ #
59
+ # _Generates_
60
+ #
61
+ # Programming%20Ruby%3A%20%20The%20Pragmatic%20Programmer%27s%20Guide
62
+ #
63
63
  def url_encode(s)
64
64
  CGI.escapeURIComponent(s.to_s)
65
65
  end
data/lib/erb/version.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
  class ERB
3
- VERSION = '5.0.2'
3
+ # The string \ERB version.
4
+ VERSION = '5.1.1'
4
5
  end