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

SQLSTATE[22001]: String data, right truncated #473

Closed
samuelreichor opened this issue May 6, 2024 · 1 comment
Closed

SQLSTATE[22001]: String data, right truncated #473

samuelreichor opened this issue May 6, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@samuelreichor
Copy link

samuelreichor commented May 6, 2024

Bug Report

We had a sql error when we wanted to add a person to a mailing list because of long UTM parameters in the url. The url from which the action was called looked like this:
https://www.karriere.at/lp/gewinnspiel-profil-check?utm_source=newsletter&utm_medium=email&utm_campaign=activesourcing_gewinnspiel_llcheck&utm_content=cta&utm_source=emarsys&utm_medium=email&utm_campaign=B2C+Active+Sourcing+April+2024+-+Lottery+%26+Tips&&sc_src=email_13853398&sc_lid=858156625&sc_uid=wx849sJloR&sc_llid=1484&sc_eh=12e5956964efdaed1

When the form on this url was submitted, a 500 error occurred and we found this error in the logs:

SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column 'source' at row 1

To test this, we truncated the get parameters as follows: https://www.karriere.at/lp/gewinnspiel-profil-check?utm_source=newsletter&utm_medium=email&utm_campaign=activesourcing_gewinnspiel_llcheck&utm_content=cta

This worked without any problems.

This is how adding the email to the mailing list is implemented:

  1. This hidden input field is in the form:
    <input type="hidden" name="action" value="campaign/forms/subscribe" />

  2. When the form gets submitted, it gets validated and this Twig file is called via ajax to determine if this email is already in the email list.

{% set mailingListSlug = craft.app.request.get('mailingList') %}
{% set email = craft.app.request.get('email') %}

{% set contact = craft.campaign.contacts.email(email).one() %}
{% set mailingLists = contact.mailingLists %}

{% set found = false %}
{% for mailingList in mailingLists %}
  {% if mailingList.slug == mailingListSlug %}
    {% set found = true %}
  {% endif %}
{% endfor %}

{{ {
  data: found ? contact : null
} | json_encode | raw }}
  1. After everything has been successfully completed, the contact gets added to the mailing list.

Our quick fix was a simple nginx redirect to strip down the get params, but hopefully there is a long term solution for that. If you need more information, feel free to ask. :)

Plugin Version

2.9.2

Craft CMS Version

4.5.11.1

PHP Version

8.2

@samuelreichor samuelreichor added the bug Something isn't working label May 6, 2024
@bencroker
Copy link
Collaborator

Thanks for reporting this. Made sure the URL is truncated to the allowed length in 972426a and released in 2.15.3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants