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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 'undefined method `encoding` for "mailto"' errors w/ Ruby 1.8 and Kramdown > 0.14.0 #1397

Merged
merged 1 commit into from Aug 8, 2013

Conversation

Projects
None yet
4 participants
@nfagerlund

nfagerlund commented Aug 8, 2013

When using Ruby 1.8.7 and Kramdown 0.14.0 and newer, the following build error
would occur if any page in your site contained a <name@example.com> email
address link:

Generating... Conversion error: There was an error converting 'contribute.markdown'.
/Users/nick/Documents/puppet-docs/vendor/bundle/ruby/1.8/gems/kramdown-1.0.2/lib/kramdown/converter/html.rb:404:in obfuscate': undefined methodencoding' for "mailto":String (NoMethodError)

See also:
http://rubyforge.org/tracker/index.php?func=detail&aid=29750&group_id=7403&atid=28673

This problem traced back to the following line in the Kramdown source:

result.force_encoding(text.encoding) if result.respond_to?(:force_encoding)

Strings aren't supposed to respond to the :force_encoding method in Ruby < 1.9,
but lib/jekyll/core_ext.rb was modifying the string class like so:

def force_encoding(enc)
self
end

Strings still won't respond to :encoding, though, so we get an error when
Kramdown tries to read the incoming encoding and everything will blow up.

An ack of the codebase suggests that this was only added so we could force an
encoding for rdiscount on 1.9 without having to check whether we were running
under 1.8. Since testing for said method to learn whether one is running under a
1.9-like encoding regime seems to be a thing in libraries we rely on, we
shouldn't insert this dummy method without also dummying every other part of the
Ruby 1.9+ encoding system.

This commit removes the dummy :force_encoding method to stop poisoning core
classes for libraries we use, and moves the adjustment for 1.9-like encoding
regimes to the one place where it's needed.

Fix 'undefined method `encoding` for "mailto"' errors w/ Ruby 1.8 and…
… Kramdown > 0.14.0

When using Ruby 1.8.7 and Kramdown 0.14.0 and newer, the following build error
would occur if any page in your site contained a `<name@example.com>` email
address link:

Generating...   Conversion error: There was an error converting 'contribute.markdown'.
/Users/nick/Documents/puppet-docs/vendor/bundle/ruby/1.8/gems/kramdown-1.0.2/lib/kramdown/converter/html.rb:404:in `obfuscate': undefined method `encoding' for "mailto":String (NoMethodError)

See also:
http://rubyforge.org/tracker/index.php?func=detail&aid=29750&group_id=7403&atid=28673

This problem traced back to the following line in the Kramdown source:

result.force_encoding(text.encoding) if result.respond_to?(:force_encoding)

Strings aren't supposed to respond to the :force_encoding method in Ruby < 1.9,
but lib/jekyll/core_ext.rb was modifying the string class like so:

def force_encoding(enc)
  self
end

Strings still won't respond to :encoding, though, so we get an error when
Kramdown tries to read the incoming encoding and everything will blow up.

An ack of the codebase suggests that this was only added so we could force an
encoding for rdiscount on 1.9 without having to check whether we were running
under 1.8. Since testing for said method to learn whether one is running under a
1.9-like encoding regime seems to be a thing in libraries we rely on, we
shouldn't insert this dummy method without also dummying every other part of the
Ruby 1.9+ encoding system.

This commit removes the dummy :force_encoding method to stop poisoning core
classes for libraries we use, and moves the adjustment for 1.9-like encoding
regimes to the one place where it's needed.
@mattr-

This comment has been minimized.

Member

mattr- commented Aug 8, 2013

Thanks for the great explanation! ❤️

👍 from me!

@parkr your turn! 😃

parkr added a commit that referenced this pull request Aug 8, 2013

Merge pull request #1397 from nfagerlund/error_187_undefined_method_e…
…ncoding_for_mailto

Fix 'undefined method `encoding` for "mailto"' errors w/ Ruby 1.8 and Kramdown > 0.14.0

@parkr parkr merged commit 3703bde into jekyll:master Aug 8, 2013

1 check passed

default The Travis CI build passed
Details

parkr added a commit that referenced this pull request Aug 8, 2013

@jekyll jekyll locked and limited conversation to collaborators Feb 27, 2017

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.