Suggested OP iframe javascript suggests a wrong split

Issue #1202 open
Matthias Keller created an issue

In #917 a correction was applied, that the session state must not contain spaces in order to be able to perform a correct split of the event data.

However, the suggested javascript code does it the wrong way if the client_id contains space(s). Then it would split at the first space, resulting in both wrong client_id and wrong session_state.

Example event data string that would break the suggested implementation (client_id is “my client”):

my client 789080e03c593a07419ad4c08bebd8e3e28909e173191b018ec24271b87cdc6c.ruyies1xuF

This would result in client_id=”my” and session_state=”client”.

Suggested fix:

Current version (30):

    var client_id = e.data.split(' ')[0];
    var session_state = e.data.split(' ')[1];

Replace with:

    var client_id = e.data.substr(0, e.data.lastIndexOf(' '));
    var session_state = e.data.substr(e.data.lastIndexOf(' ') + 1);

Comments (2)

  1. Log in to comment