When trying to set a source imagefile with an upper-cased extension (ie 'JPG') using setSourceImageFile, the module throws an Exception:
Drupal\textimage\TextimageException: Textimage error: Attempted to set an unsupported file image extension (JPG) in Drupal\textimage\Textimage->setTargetExtension() (line 314 of /httpdocs/modules/textimage/src/Textimage.php).
Turns out the returned Array from $this->imageFactory->getSupportedExtensions() is all in lower-case.
So even when (in my case) the returned Array is:
array(5)
string(3) "gif"
string(3) "jpe"
string(4) "jpeg"
string(3) "jpg"
string(3) "png"
which has "jpg" in the a file like 'example.JPG' isn't accepted.
| Comment | File | Size | Author |
|---|---|---|---|
| #9 | 2810123-9.patch | 2.05 KB | spokje |
Comments
Comment #2
mondrakeThanks for the report @Spokje
This should be easy to fix: the setTargetExtension method is not converting to lower the extension passed in before checking against the valid ones.
Also, would need a test in TextimageApiTest to prevent future regressions.
Comment #3
spokjeAs mondrake suggested in #2: Patch includes new test-case and lower-casing file extension before do the check.
Since I'm new to the Patching and TestCasing business, there are endless possibilities I made errors, please feel free to point them out.
Comment #4
spokjeComment #5
mondrakePatch looks great! Just a few points:
1. You have some whitespace (or tabs?) at the end of the lines. Please remove any trailing space and/or convert tabs to spaces, according to coding standards.
2.
This comment is exceeding 80 chars. Please trim exceeding chars and put in a new line.
3.
You may also want to assert that the file extension of
$textimage->getUri()is actually a '.png' (lowercase).4.
Let's do a
$extension = strtolower($extension);before the if block, and leave the if untouched. This way we will store the lowercased extension in any case, which is better as in all the image system the extensions are represented lowercase.Comment #6
spokjeThanks, all are valid remarks. Should all be fixed in the newly added patch.
Comment #7
spokjeGrmbl, I've seem to manage to type one message without an English grammar error, and then miscounted the comment#, so patch 2810123-5.patch should be named 2810123-6.patch.
Comment #8
mondrakeThank you. Last two more things from me then :)
Each line should be as close as possible to 80 chars. I can fix it on commit, do not worry, but just be aware that this is the coding standard and you will find similar remarks especially when you will be proposing patches for Drupal core :)
why not using
$image_file_extension = pathinfo($textimage->getUri(), PATHINFO_EXTENSION);instead?Also, it would be good to include interdiffs in new patches :)
Comment #9
spokjeThanks @Mondrake for dragging me along here.
All remarks should be addressed in patch 2810123-9.patch, except for the interdiffs (which I solemnly promise to setup for the next patch ;).
Comment #10
spokjeComment #11
mondrakeLooks good now, thanks. Setting to RTBC if anyone will have more comments; not much reviews of patches in this module - if no more input in next couple days I will commit this.
Comment #12
mondrakeComment #13
mondrakeComment #15
mondrakeCommitted. Thank you @Spokje!
Comment #16
mondrakeComment #18
spokje