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] Beautifer stops beautifying halfway through the file #2146

Open
Jonius7 opened this issue May 3, 2023 · 1 comment
Open

[Python] Beautifer stops beautifying halfway through the file #2146

Jonius7 opened this issue May 3, 2023 · 1 comment

Comments

@Jonius7
Copy link

Jonius7 commented May 3, 2023

Description

For 3 years, SteamUI-OldGlory has used the python library jsbeautifier to beautify the JS code included with Steam with no problems. However, in a recent update the beautifying process has stopped working halfway through the original file.

Input

The file in question is chunk~2dcc5aaf7.js, since it's over 7MB I'll post it on Mediafire if needed and add snippets here to the issue:
https://www.mediafire.com/file/g1zbcexf09eb7y0/chunk%257E2dcc5aaf7.js/file
The code looked like this before beautification (snippet below):

let n=l.IE.fromObject({accountid_owner:e.GetAccountID()});this.OnNotification(this.m_nNextTestNotificationID++,13,n.serializeBinary())}TestAchievement(e){return(0,n.mG)(this,void 0,void 0,(function*(){if(!e)return void console.log("provide the appid for a game you own that also has achievements");const t=yield m.d.RequestAppDetails(e);let r=null;if(t&&0!=t.achievements.vecHighlight.length){let e=a.RandomInt(0,t.achievements.vecHighlight.length-1);r=t.achievements.vecHighlight[e]}else console.log("TestAchievement - Couldn't find app details or highlighted achievements for "+e+" so making one up."),r={strName:"won a race",strDescription:"You placed 1st!",strImage:"https://cdn.cloudflare.steamstatic.com/steamcommunity/public/images/apps/270880/2aec8af4b4b23cb6054d9aea06194621cdd66945.jpg",strID:"1"};let n={achievement_id:r.strID,appid:e,name:r.strName,description:r.strDescription,image_url:r.strImage,achieved:!0,rtime_unlocked:1622670460,current_progress:0,max_progress:0,min_progress:0,global_achieved_pct:10},i=l.fT.fromObject(n);this.OnNotification(this.m_nNextTestNotificationID++,5,i.serializeBinary())}))}

Expected Output

The code should have looked like this after beautification:

let n = l.IE.fromObject({
    accountid_owner: e.GetAccountID()
});
this.OnNotification(this.m_nNextTestNotificationID++, 13, n.serializeBinary())
}
TestAchievement(e) {
    return (0, n.mG)(this, void 0, void 0, (function*() {
        if (!e) return void console.log("provide the appid for a game you own that also has achievements");
        const t = yield m.d.RequestAppDetails(e);
        let r = null;
        if (t && 0 != t.achievements.vecHighlight.length) {
            let e = a.RandomInt(0, t.achievements.vecHighlight.length - 1);
            r = t.achievements.vecHighlight[e]
        } else console.log("TestAchievement - Couldn't find app details or highlighted achievements for " + e + " so making one up."), r = {
            strName: "won a race",
            strDescription: "You placed 1st!",
            strImage: "https://cdn.cloudflare.steamstatic.com/steamcommunity/public/images/apps/270880/2aec8af4b4b23cb6054d9aea06194621cdd66945.jpg",
            strID: "1"
        };
        let n = {
                achievement_id: r.strID,
                appid: e,
                name: r.strName,
                description: r.strDescription,
                image_url: r.strImage,
                achieved: !0,
                rtime_unlocked: 1622670460,
                current_progress: 0,
                max_progress: 0,
                min_progress: 0,
                global_achieved_pct: 10
            },
            i = l.fT.fromObject(n);
        this.OnNotification(this.m_nNextTestNotificationID++, 5, i.serializeBinary())
    }))
}

Actual Output

The code actually looked like this after beautification:

let n = l.IE.fromObject({
    accountid_owner: e.GetAccountID()
});
this.OnNotification(this.m_nNextTestNotificationID++, 13, n.serializeBinary())
}
TestAchievement(e) {
    return (0, n.mG)(this, void 0, void 0, (function*() {
        if (!e) return void console.log("provide the appid for a game you own that also has achievements");
        const t = yield m.d.RequestAppDetails(e);
        let r = null;
        if (t && 0 != t.achievements.vecHighlight.length) {
            let e = a.RandomInt(0, t.achievements.vecHighlight.length - 1);
            r = t.achievements.vecHighlight[e]
        } else console.log("TestAchievement - Couldn't find app details or highlighted achievements for " + e + " so making one up."), r = {
            strName: "won a race",
            strDescription: "You placed 1st!",
            strImage: "https://cdn.cloudflare.steamstatic.com/steamcommunity/public/images/apps/270880/2aec8af4b4b23cb6054d9aea06194621cdd66945.jpg",strID: "1"};let n = {achievement_id: r.strID,appid: e, name: r.strName,description: r.strDescription,image_url: r.strImage, achieved: !0,rtime_unlocked: 1622670460,current_progress: 0,max_progress: 0,min_progress: 0,global_achieved_pct: 10},i = l.fT.fromObject(n);this.OnNotification(this.m_nNextTestNotificationID++, 5, i.serializeBinary())}))}

That is, after the https://, the rest of the code refused to beautify and was on 1 line. Is the file too big or are there too many special characters? eg: (!, /)

Steps to Reproduce

Obtain a copy of chunk~2dcc5aaf7.js (located in [Steam Directory]/steamui)
Attempt to beautify the JS file with the following Python code:

import jsbeautifier

def beautify_js(filename):
    beautify_file = get_beaut_filename(filename)
    opts = jsbeautifier.default_options()
    library = jsbeautifier.beautify_file(filename, opts)
    f = open(beautify_file, "wt", newline='', encoding="UTF-8")
    f.write(library)
    f.close()

def get_beaut_filename(filename):
    beaut_filename = filename.rsplit(".", 1)
    return beaut_filename[0] + ".beaut." + beaut_filename[1]

Inspect the output file chunk~2dcc5aaf7.beaut.js
A copy of the output file is provided here: https://www.mediafire.com/file/erg8zpirhbifr7n/chunk%257E2dcc5aaf7.beaut.js/file

Environment

OS: Windows 11, Python 3.8.16

Settings

Default settings

@Jonius7 Jonius7 changed the title Beautifer stops beautifying halfway through the file [Python] Beautifer stops beautifying halfway through the file May 3, 2023
@bitwiseman
Copy link
Member

Is the file too big or are there too many special characters? eg: (!, /)

It is more likely that there's a some part of that URL that is getting recognized wrong. Please try changing the URL to be something shorter/simpler and see what happens.

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