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

Product description_plaintext blocks are improperly concatenated. #7599

Closed
4 of 9 tasks
daltonsena opened this issue Jul 8, 2021 · 1 comment
Closed
4 of 9 tasks
Labels

Comments

@daltonsena
Copy link
Contributor

daltonsena commented Jul 8, 2021

What I'm trying to achieve

When I was testing the description field with broader texts and terms to achieve good search results, a small issue came to me. I can't affirm if this is a bug or expected behaviour, but I would like to expose this line of thought.

The potential bug is:

Either as sanitizer of the description field or by invocation of the method (e.g., product mutation), when the clean_editor_js method is required, blocks (EditorJS JSON definitions) might be being wrongly concatenated.

As a result, the search vector will be populated with terms that might not make sense.

Steps to reproduce the problem

  1. Let's grab the default demo database and the product "Apple Juice" (in my case id 72)
    Screen Shot 2021-07-07 at 23 05 39
[
  {
    "id": 72,
    "name": "Apple Juice",
    "description": "{\"time\": 1625709710445, \"blocks\": [{\"data\": {\"text\": \"Fell straight from the tree, on to Newton’s head, then into the bottle. The autumn taste of English apples. Brought to you by gravity.\"}, \"type\": \"paragraph\"}], \"version\": \"2.20.0\"}",
    "updated_at": "2021-07-08 02:04:19.359545",
    "product_type_id": 9,
    "category_id": 14,
    "seo_description": "Fell straight from the tree, on to Newton’s head, then into the bottle. The autumn taste of English apples. Brought to you by gravity.",
    "seo_title": "",
    "charge_taxes": true,
    "weight": 1000,
    "metadata": "{\"vatlayer.code\": \"standard\", \"vatlayer.description\": \"standard\"}",
    "private_metadata": "{}",
    "slug": "apple-juice",
    "default_variant_id": 202,
    "description_plaintext": "Fell straight from the tree, on to Newton’s head, then into the bottle. The autumn taste of English apples. Brought to you by gravity.",
    "search_vector": "'appl':1A,22B 'autumn':18B 'bottl':16B 'brought':23B 'english':21B 'fell':3B 'graviti':27B 'head':12B 'juic':2A 'newton':10B 'straight':4B 'tast':19B 'tree':7B",
    "rating": null
  }
]

The result of description_plaintext and the search_vector fields are:

Fell straight from the tree, on to Newton’s head, then into the bottle. The autumn taste of English apples. Brought to you by gravity.

  • 'appl':1A,22B
  • 'autumn':18B
  • 'bottl':16B
  • 'brought':23B
  • 'english':21B
  • 'fell':3B
  • 'graviti':27B
  • 'head':12B
  • 'juic':2A
  • 'newton':10B
  • 'straight':4B
  • 'tast':19B
  • 'tree':7B"
  1. Let's insert some additional texts on the description field
    Screen Shot 2021-07-07 at 23 21 12
  {
    "id": 72,
    "name": "Apple Juice",
    "description": "{\"time\": 1625710749431, \"blocks\": [{\"data\": {\"text\": \"Fell straight from the tree, on to Newton’s head, then into the bottle. The autumn taste of English apples. Brought to you by gravity.\"}, \"type\": \"paragraph\"}, {\"data\": {\"text\": \"Apple juice is 88% water and 11% carbohydrates (including 9% sugars), with negligible content of protein or fat.\"}, \"type\": \"paragraph\"}, {\"data\": {\"items\": [\"organic fabrication\", \"toxin-free \", \"healthy lifestyle\", \"made with love\"], \"style\": \"ordered\"}, \"type\": \"list\"}], \"version\": \"2.20.0\"}",
    "updated_at": "2021-07-08 02:19:13.819220",
    "product_type_id": 9,
    "category_id": 14,
    "seo_description": "Fell straight from the tree, on to Newton’s head, then into the bottle. The autumn taste of English apples. Brought to you by gravity.",
    "seo_title": "",
    "charge_taxes": true,
    "weight": 1000,
    "metadata": "{\"vatlayer.code\": \"standard\", \"vatlayer.description\": \"standard\"}",
    "private_metadata": "{}",
    "slug": "apple-juice",
    "default_variant_id": 202,
    "description_plaintext": "Fell straight from the tree, on to Newton’s head, then into the bottle. The autumn taste of English apples. Brought to you by gravity.Apple juice is 88% water and 11% carbohydrates (including 9% sugars), with negligible content of protein or fat.organic fabricationtoxin-free healthy lifestylemade with love",
    "search_vector": "'11':33B '88':30B '9':36B 'appl':1A,22B 'autumn':18B 'bottl':16B 'brought':23B 'carbohydr':34B 'content':40B 'english':21B 'fabricationtoxin':46B 'fabricationtoxin-fre':45B 'fat.organic':44B 'fell':3B 'free':47B 'gravity.apple':27B 'head':12B 'healthi':48B 'includ':35B 'juic':2A,28B 'lifestylemad':49B 'love':51B 'neglig':39B 'newton':10B 'protein':42B 'straight':4B 'sugar':37B 'tast':19B 'tree':7B 'water':31B",
    "rating": null
  }

The result of description_plaintext and the search_vector fields are:

Fell straight from the tree, on to Newton’s head, then into the bottle. The autumn taste of English apples. Brought to you by gravity.Apple❗ juice is 88% water and 11% carbohydrates (including 9% sugars), with negligible content of protein or fat.organicfabricationtoxin-free❗ healthy lifestylemade❗ with love

  • '11':33B
  • '88':30B
  • '9':36B
  • 'appl':1A,22B
  • 'autumn':18B
  • 'bottl':16B
  • 'brought':23B
  • 'carbohydr':34B
  • 'content':40B
  • 'english':21B
  • 'fabricationtoxin':46B
  • 'fabricationtoxin-fre':45B
  • 'fat.organic':44B
  • 'fell':3B
  • 'free':47B
  • 'gravity.apple':27B
  • 'head':12B
  • 'healthi':48B
  • 'includ':35B
  • 'juic':2A,28B
  • 'lifestylemad':49B
  • 'love':51B
  • 'neglig':39B
  • 'newton':10B
  • 'protein':42B
  • 'straight':4B
  • 'sugar':37B
  • 'tast':19B
  • 'tree':7B
  • 'water':31B"

What I expected to happen

I think the method clean_editor_js can separate each block with space.

System information

Saleor version:

  • dev (current master)
  • 3.0
  • 2.11
  • 2.10

Operating system:

  • Windows
  • Linux
  • MacOS
  • Docker
  • Other
@daltonsena daltonsena added the bug label Jul 8, 2021
maarcingebala pushed a commit that referenced this issue Jul 9, 2021
* fix: fixes issue #7599
Signed-off-by: Dalton <daltonsena@users.noreply.github.com>

* - changing clean_editor_js to add the results to a list
- fixing test_clean_editor_js_for_list

Signed-off-by: Dalton <daltonsena@users.noreply.github.com>

* removing commented unused code
Signed-off-by: Dalton <daltonsena@users.noreply.github.com>

* chore: renaming variable "string" to "plain_text_list" for better
understanding
Signed-off-by: Dalton <daltonsena@users.noreply.github.com>

* add new test_clean_editor_js_for_complex_description for editorjs

Signed-off-by: Dalton <daltonsena@users.noreply.github.com>

Co-authored-by: Dalton <daltonsena@users.noreply.github.com>
@krzysztofwolski
Copy link
Member

PR with the fix merged

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

No branches or pull requests

2 participants