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

Strange behaviour using functions #170

Closed
Braste opened this issue May 2, 2024 · 1 comment
Closed

Strange behaviour using functions #170

Braste opened this issue May 2, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@Braste
Copy link

Braste commented May 2, 2024

If I do this

export default (_context: Context, args: unknown) => { 
    $db.us(
        {
            _id: 'harvest'
        },
        {
            _id: 'harvest',
            filter: ['.pub', '.entry'],
            blacklist: ['accenture',
                'arino',
                'blackcore',
                'blackstar',
                'dynamo_corp',
                'jinteki_corp',
                'l4sh',
                'lunar_systems',
                'n_inc',
                'onion',
                'perimeter_systems',
                'ploogle',
                'pwnhub',
                'reinit',
                'rozas',
            ],
            commandRegex: 'with ([a-z`$]+):"([a-z]+)',
            userRegex: '([a-z0-9_]+) (of project|when being)',
            projectRegex: '(date for|continues on|of the|developments on|of project|review of).([a-z0-9.`_]+)',
            passwordRegex: 'strategy.([a-z0-9_]+)'
        }
    )
}

i get down to 74 chars.

If I do this

export default (_context: Context, args: unknown) => { 
    i();
}
function i() {
    $db.us(
        {
            _id: 'harvest'
        },
        {
            _id: 'harvest',
            filter: ['.pub', '.entry'],
            blacklist: ['accenture',
                'arino',
                'blackcore',
                'blackstar',
                'dynamo_corp',
                'jinteki_corp',
                'l4sh',
                'lunar_systems',
                'n_inc',
                'onion',
                'perimeter_systems',
                'ploogle',
                'pwnhub',
                'reinit',
                'rozas',
            ],
            commandRegex: 'with ([a-z`$]+):"([a-z]+)',
            userRegex: '([a-z0-9_]+) (of project|when being)',
            projectRegex: '(date for|continues on|of the|developments on|of project|review of).([a-z0-9.`_]+)',
            passwordRegex: 'strategy.([a-z0-9_]+)'
        }
    )
}

I get 208 chars.

@samualtnorman
Copy link
Owner

samualtnorman commented May 2, 2024

the 208 char script is this:

function(){
//	["harvest","filter",".pub",".entry","blacklist","accenture","arino","blackcore","blackstar","dynamo_corp","jinteki_corp","l4sh","lunar_systems","n_inc","onion","perimeter_systems","ploogle","pwnhub","reinit","rozas","commandRegex","with ([a-z`$]+):\"([a-z]+)","userRegex","([a-z0-9_]+) (of project|when being)","projectRegex","(date for|continues on|of the|developments on|of project|review of).([a-z0-9.`_]+)","passwordRegex","strategy.([a-z0-9_]+)"]	
let[$,s,t,c,d,i,_,q,S,k,z,I,e,n,p,u,P,T,l,r,B,C,D,N,R,a,f,o]=JSON.parse(#fs.scripts.quine().split`	`[1])
#db.us({_id:$},{_id:$,[s]:[t,c],[d]:[i,_,q,S,k,z,I,e,n,p,u,P,T,l,r],[B]:C,[D]:N,[R]:a,[f]:o})}

This is because the object and array literals are inside a function which means my code thinks it's not safe for quine-cheating. It's generally not safe for quine-cheating because functions can be called multiple times and the object and array literals should evaluate to unique instances every time.

If the whole object was quine-cheated, every time you call the function, it would be the same instance which does not follow normal JavaScript semantics.

Now what my code doesn't know is that the function is called only once so it's not a big deal. I could add a detection for this, however this use-case is mostly solved by fixing/implementing #157.

You can close this issue if you think #157 covers this issue or you keep it open and later decide if this is solved when #157 fixed/implemented.

@samualtnorman samualtnorman added the enhancement New feature or request label May 2, 2024
@Braste Braste closed this as completed May 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants