Skip to content
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

Python jsbeautifier fails for special chars #1809

Closed
virajkanwade opened this issue Jul 1, 2020 · 0 comments
Closed

Python jsbeautifier fails for special chars #1809

virajkanwade opened this issue Jul 1, 2020 · 0 comments
Milestone

Comments

@virajkanwade
Copy link
Contributor

Description

This is the default template for bug reports

NOTE:

  • Do not include screenshots! This library is a text processor, we need text inputs and outputs for debugging and fixing issues.
  • Check the list of open issues before filing a new issue.

If the packed code contains special characters it results in an exception. The online beautifier works for the same.

Input

The code looked like this before beautification:

eval(function(p,a,c,k,e,d){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--){d[e(c)]=k[c]||e(c)}k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1};while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c])}}return p}('1D(1p(p,a,c,k,e,d){e=1p(c){1q(c<a?\'\':e(1Y(c/a)))+((c=c%a)>1X?1u.1W(c+29):c.1V(1U))};1s(!\'\'.1r(/^/,1u)){1t(c--){d[e(c)]=k[c]||e(c)}k=[1p(e){1q d[e]}];e=1p(){1q\'\\\\w+\'};c=1};1t(c--){1s(k[c]){p=p.1r(1S 1R(\'\\\\b\'+e(c)+\'\\\\b\',\'g\'),k[c])}}1q p}(\'0.W=\\\'E+F=\\\';q r={\\\'J\\\':\\\'16:9\\\',\\\'M\\\':6,\\\'N\\\':5,\\\'O\\\':6,\\\'P\\\':5,\\\'Q\\\':\\\'//R.p.S.T/t/v/7.12.11/0.U.x\\\',\\\'L\\\':K,\\\'y\\\':6,\\\'I\\\':1,\\\'H\\\':{\\\'G\\\':{}},\\\'D\\\':\\\'C\\\',\\\'B\\\':\\\'A\\\',\\\'z\\\':6,\\\'V\\\':6,\\\'X\\\':\\\'19\\\',\\\'1n\\\':5,\\\'1m\\\':\\\'1l%\\\'};0.1k=r;q s=0(\\\'1j\\\');s.o({l:[{2:\\\'#\\\',8:\\\'1h\\\',3:\\\'k\\\',}],1g:\\\'\\\',1f:\\\'\\\',j:[{\\\'i\\\':\\\'5\\\',\\\'2\\\':\\\'\\\',\\\'g\\\':\\\'4\\\',\\\'3\\\':\\\'\\\'}],4:{b:\\\'#f\\\',h:14,m:a},});0().c(\\\'d\\\',e(){0().o({l:[{2:\\\'{Íâ–+›ï;ã†Ù¥#\\\',8:\\\'n\\\',3:\\\'k\\\',}],j:[{\\\'i\\\':\\\'5\\\',\\\'2\\\':\\\'\\\',\\\'g\\\':\\\'4\\\',\\\'3\\\':\\\'\\\'}],4:{b:\\\'#f\\\',h:14,m:a},w:\\\'\\\',});0().u();0().c(\\\'d\\\',e(){0().1e({l:[{2:\\\'{Íâ–+›ï;ã†Ù¥#\\\',8:\\\'n\\\',3:\\\'k\\\',}],j:[{\\\'i\\\':\\\'5\\\',\\\'2\\\':\\\'\\\',\\\'g\\\':\\\'4\\\',\\\'3\\\':\\\'\\\'}],4:{b:\\\'#f\\\',h:14,m:a},w:\\\'\\\',});0().u();0().c(\\\'d\\\',e(){0().1c();18.17=\\\'15://13.10.Z/t.1o?8=Y&1a=1b&1d=1&1i=1\\\'})})});\',1Q,1Z,\'21||22|23|24|25|26||1O||28|20|1P|1H|1p|1w|1x|2b|1y|1z|1A|1B|1C|1v|1E||1F|1G|1N|1I|1J||1K|1L|1M|2a|27|2c|2r|2D|2E|2F|2G|2L|2H|2I|2J|2K|2B|2M|2V|2U|2T|2S|2R|2Q|2P|2O|2N|2C|2A|2o|2y|||2e||2f||2g|2h|2i|2j|2k|2l|2m|2d|2n|2p|2q|2z|2s|2t|2u|2v|2w|2x\'.1T(\'|\'),0,{}))',62,182,'|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||function|return|replace|if|while|String|hls|FFFF00|kind|default|tracks|hd|sources|backgroundOpacity|eval|setup|var|jwDefaults|error|player|play|logo|swf|mute|playerInstance|type|on|62|RegExp|new|split|36|toString|fromCharCode|35|parseInt|87|color|jwplayer|file|label|captions|true|false|html5|50||repeat|fontSize|primary|load|database|https|location|window|uniform|imdb|tt6468322|remove|season|title|me|image|mp4|auto|picasa|defaults|100|width|visualplaylist|php|gdriveplayer|episode|series|autostart|stretching|preload|hPszQQp|IqjcUlhpmrTh5ScOfBhQ7glGcHH2f7l1RhA|ping|ph|aspectratio|260|height|plugins|controls|key|stagevideo|flash|com|jwpcdn|ssl|flashplayer|displaytitle|displaydescription'.split('|'),0,{}))

Expected Output

The code should have looked like this after beautification:

jwplayer.key = 'hPszQQp+IqjcUlhpmrTh5ScOfBhQ7glGcHH2f7l1RhA=';
var jwDefaults = {
    'aspectratio': '16:9',
    'autostart': false,
    'controls': true,
    'displaydescription': false,
    'displaytitle': true,
    'flashplayer': '//ssl.p.jwpcdn.com/player/v/7.12.11/jwplayer.flash.swf',
    'height': 260,
    'mute': false,
    'ph': 1,
    'plugins': {
        'ping': {}
    },
    'preload': 'auto',
    'primary': 'html5',
    'repeat': false,
    'stagevideo': false,
    'stretching': 'uniform',
    'visualplaylist': true,
    'width': '100%'
};
jwplayer.defaults = jwDefaults;
var playerInstance = jwplayer('picasa');
playerInstance.setup({
    sources: [{
        file: '#',
        type: 'mp4',
        label: 'hd',
    }],
    image: '',
    title: '',
    tracks: [{
        'default': 'true',
        'file': '',
        'kind': 'captions',
        'label': ''
    }],
    captions: {
        color: '#FFFF00',
        fontSize: 14,
        backgroundOpacity: 50
    },
});
jwplayer().on('error', function() {
    jwplayer().setup({
        sources: [{
            file: '{Íâ–+›ï;ã†Ù¥#',
            type: 'hls',
            label: 'hd',
        }],
        tracks: [{
            'default': 'true',
            'file': '',
            'kind': 'captions',
            'label': ''
        }],
        captions: {
            color: '#FFFF00',
            fontSize: 14,
            backgroundOpacity: 50
        },
        logo: '',
    });
    jwplayer().play();
    jwplayer().on('error', function() {
        jwplayer().load({
            sources: [{
                file: '{Íâ–+›ï;ã†Ù¥#',
                type: 'hls',
                label: 'hd',
            }],
            tracks: [{
                'default': 'true',
                'file': '',
                'kind': 'captions',
                'label': ''
            }],
            captions: {
                color: '#FFFF00',
                fontSize: 14,
                backgroundOpacity: 50
            },
            logo: '',
        });
        jwplayer().play();
        jwplayer().on('error', function() {
            jwplayer().remove();
            window.location = 'https://database.gdriveplayer.me/player.php?type=series&imdb=tt6468322&season=1&episode=1'
        })
    })
});

Actual Output

The code actually looked like this after beautification:

  File "/opt/.venv/lib/python3.8/site-packages/jsbeautifier/__init__.py", line 76, in beautify
    return b.beautify(string, opts)
  File "/opt/.venv/lib/python3.8/site-packages/jsbeautifier/javascript/beautifier.py", line 175, in beautify
    source_text = self.unpack(source_text, self._options.eval_code)
  File "/opt/.venv/lib/python3.8/site-packages/jsbeautifier/javascript/beautifier.py", line 257, in unpack
    return unpackers.run(source, evalcode)
  File "/opt/.venv/lib/python3.8/site-packages/jsbeautifier/unpackers/__init__.py", line 49, in run
    source = unpacker.unpack(source)
  File "/opt/.venv/lib/python3.8/site-packages/jsbeautifier/unpackers/packer.py", line 64, in unpack
    source = re.sub(r'\b\w+\b', lookup, payload)
  File "/opt/.pyenv/versions/3.8.3/lib/python3.8/re.py", line 210, in sub
    return _compile(pattern, flags).sub(repl, string, count)
  File "/opt/.venv/lib/python3.8/site-packages/jsbeautifier/unpackers/packer.py", line 62, in lookup
    return symtab[unbase(word)] or word
  File "/opt/.venv/lib/python3.8/site-packages/jsbeautifier/unpackers/packer.py", line 142, in __call__
    return self.unbase(string)
  File "/opt/.venv/lib/python3.8/site-packages/jsbeautifier/unpackers/packer.py", line 150, in _dictunbaser
    ret += (self.base ** index) * self.dictionary[cipher]
KeyError: 'â'

Steps to Reproduce

Environment

OS:
Mac Catalina + Python 3.8.3

Settings

Example:

{
    "indent_size": 4,
    "indent_char": " ",
    "indent_level": 0,
    "indent_with_tabs": false,
    "preserve_newlines": true,
    "max_preserve_newlines": 10,
    "jslint_happy": false,
    "space_after_anon_function": false,
    "brace_style": "collapse,preserve-inline",
    "keep_array_indentation": false,
    "keep_function_indentation": false,
    "space_before_conditional": true,
    "break_chained_methods": false,
    "eval_code": false,
    "unescape_strings": false,
    "wrap_line_length": 0
}
virajkanwade added a commit to virajkanwade/js-beautify that referenced this issue Jul 1, 2020
virajkanwade added a commit to virajkanwade/js-beautify that referenced this issue Jul 1, 2020
@bitwiseman bitwiseman added this to the v1.11.x milestone Jul 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants