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

Fixes PreserveKey not being passed from a redirect (#522) #526

Merged
merged 4 commits into from
Jan 21, 2021

Conversation

tonyjunkes
Copy link
Member

This is a duplicate pull request of pull 523 but because I reset my local develop repo, it removed the commit and closed the original pull request. The price I pay for not creating a specific issue branch originally. Sorry about that.

Copied original pull details here...

Issue:

In Lucee, localmode="modern" is extremely strict with what scopes are referenced/available in the chain. Especially when a function within a function accepts a closure. This makes external local and variables scopes unavailable unless directly passed and returned for further use.

Fix:

The committed fix sets localmode="classic" in the function expression passed into sessionLock() inside of getNextPreserveKeyAndPurgeOld(). This allows FW/1's flash context to work as expected, regardless of the number of contexts, in both Lucee and Adobe ColdFusion (since the attribute is simply ignored).

Note On Alternative Approaches:

If it's preferred to avoid engine specific mechanics in the code, an alternative approach is to define both the "next" and "old" keys to session variables that are accessible to all levels of the execution chain in getNextPreserveKeyAndPurgeOld().

private string function getNextPreserveKeyAndPurgeOld() {
        try {
            sessionLock(function(){
                sessionDefault( '__fw1NextPreserveKey', 0 );
                sessionDefault( '__fw1OldKeyToPurge', '' );
                if ( variables.framework.maxNumContextsPreserved > 1 ) {
                    sessionWrite( '__fw1NextPreserveKey', sessionRead( '__fw1NextPreserveKey' ) + 1 );
                    sessionWrite( '__fw1OldKeyToPurge', sessionRead( '__fw1NextPreserveKey' ) - variables.framework.maxNumContextsPreserved );
                } else {
                    sessionWrite( '__fw1NextPreserveKey', '' );
                    sessionWrite( '__fw1PreserveKey', '' );
                }
            });
            var key = getPreserveKeySessionKey( sessionRead( '__fw1OldKeyToPurge' ) );
            if ( sessionHas( key ) ) {
                sessionDelete( key );
            }
        } catch ( any e ) {
            // ignore - assume session scope is disabled
        }
        return sessionRead( '__fw1NextPreserveKey' );
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants