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

Unexpected end of JSON input error occurs in default state #17

Open
castor4bit opened this issue Aug 21, 2023 · 0 comments
Open

Unexpected end of JSON input error occurs in default state #17

castor4bit opened this issue Aug 21, 2023 · 0 comments

Comments

@castor4bit
Copy link

Problems summary

Unexpected end of JSON input error occurs due to incorrect initial value when there is no value in localStorage.

Uncaught SyntaxError: Unexpected end of JSON input
    at JSON.parse (<anonymous>)
    at Object.generateOneLinkURL (onelink-smart-script-v2.7.0.js:2207:33)
    at test.html:12:43

This may be due to the following code, where the correct initial value is probably [].
https://github.com/AppsFlyerSDK/appsflyer-onelink-smart-script/blob/main/scripts/onelink-smart-script-v2.7.0.js#L2207

- var webReferrerValue = JSON.parse(localStorage.getItem(LOCAL_STORAGE_VALUES.SS_WEB_REFERRER) || '');
+ var webReferrerValue = JSON.parse(localStorage.getItem(LOCAL_STORAGE_VALUES.SS_WEB_REFERRER) || '[]');

Expected

No errors.

Environment Information

  • macOS 11.7.8
  • Google Chrome Version 115.0.5790.170 (Official Build) (x86_64)
  • onelink-smart-script
    • onelink-smart-script-v2.7.1.js
    • onelink-smart-script-v2.7.0.js
    • (not reproduced in v2.6.0)

How to reproduce

  • Access page 1 without ss_webReferrer in localStorage
  • Click the link to reproduce

sample code

<!DOCTYPE html>
<html>
<body>
  <a href="test.html">go to test page</a>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
  <script src="onelink-smart-script-v2.7.1.js"></script>
</head>
<body>
  <span id="output_url">no data</span>

  <script type="text/javascript">
      var oneLinkURL = "https://engmntqa.onelink.me/LtRd/";
      var mediaSource = {defaultValue: "my_media_default_source"};
      var result = window.AF_SMART_SCRIPT.generateOneLinkURL({
        oneLinkURL,
        afParameters:{
          mediaSource: mediaSource
        }
      })
      if (result) {
        document.getElementById('output_url').innerHTML = result.clickURL;
      }
  </script>
</body>
</html>
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

No branches or pull requests

1 participant