Git Product home page Git Product logo

Comments (5)

michas2 avatar michas2 commented on August 19, 2024

Allright, I think I found the bug in chain/uri_resolver.rb:

sprintf('%%%X', match.unpack($KCODE == 'UTF8' ? 'U' : 'c')[0])

The lowercase "c" unpacks a signed Integer, which will in this case always be negativ, causing sprintf to generate garbage. Just substituting the lowercase "c" by a uppercase "C" to get an unsigned value should do exactly the right thing.

from mechanize.

michas2 avatar michas2 commented on August 19, 2024

There seems to be another issue: (even after fixing the above unpack)

Mechanize.new.get("http://localhost:4567/?query=müller").content # YES
Mechanize.new.get("http://localhost:4567/?query=müller").links[0].click.content # NO
Mechanize.new.get("http://localhost:4567/?query=müller").links[0].href # "?query=m\347\253\257ller"

Seems there is something broken while parsing the link.
page.content looks fine, but the extracted link is not correctly encoded.

from mechanize.

michas2 avatar michas2 commented on August 19, 2024

If the Server didn't supply a proper encoding[1], the constructor of Mechanize::Page guesses the encoding:

@encoding ||= Util.detect_charset(body)

That encoding is given to Nokogiri, which tries to "decode" all strings based on that encoding.

Commenting out the above line solved the problem. This works for me, but it surely might break cases where encoding is actually important. - Please give the user an option to set an own default encoding and only try to guess it if there is no other way.

[1]: there seems to be a minor issue if the server sent something like "CharSet".

        next unless v =~ /charset/i # case insensitive
        encoding = v[/charset=([^; ]+)/, 1] #case sensitive

from mechanize.

drbrain avatar drbrain commented on August 19, 2024

I have fixed the unpack and made the charset be case insensitive but I can't fix (or provide a workaround for) the encoding auto-detect without a test case.

from mechanize.

drbrain avatar drbrain commented on August 19, 2024

encoding auto-detect seems to be covered by other bugs in the issues tracker.

from mechanize.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.