Problem/Motivation
Creating a site for a Cutstomer that wants to provide Parasolid files to his Partners.
those files have the extensions .x_t and .x_b
source: https://en.wikipedia.org/wiki/Parasolid
When trying to define the File Field I get:
The list of allowed extensions is not valid, be sure to exclude leading dots and to separate extensions with a comma or space.
Steps to reproduce
1. Ad a file field to a node
2. try to set the allowed Extensions to "x_t x_b"
3. try to save the Field settings
Proposed resolution
Allow '_' as a valid extension character
User interface text changes.
Allowed files extension help text:
Separate extensions with a comma or space. Each extension can contain alphanumeric characters, '.', and '_', and should start and end with an alphanumeric character.
Error message:
The list of allowed extensions is not valid. Allowed characters are a-z, 0-9, '.', and '_'. The first and last characters cannot be '.' or '_', and these two characters cannot appear next to each other. Separate extensions with a comma or space.
Remaining tasks
None
User interface changes
Setting page for the file field, i.e. /admin/structure/types/manage/article/fields/node.article.field_file.
Before
After
API changes
afaik none
Data model changes
afaik none
Release notes snippet
Allow configuring file extensions with a underscore ie. x_t via the UI
Comment | File | Size | Author |
---|---|---|---|
#60 | interdiff_53_60.txt | 3.2 KB | anmolgoyal74 |
#60 | 3166044-60.patch | 3.69 KB | anmolgoyal74 |
#60 | 3166044-60-test-only.patch | 1.74 KB | anmolgoyal74 |
#55 | Before - Description.png | 16.71 KB | anmolgoyal74 |
#55 | After - description.png | 20.17 KB | anmolgoyal74 |
Comments
Comment #2
spuky CreditAttribution: spuky as a volunteer commentedsorry wrong patch format...
Comment #3
spuky CreditAttribution: spuky as a volunteer commentedComment #4
spuky CreditAttribution: spuky as a volunteer commentedIssue: https://www.drupal.org/project/drupal/issues/997900
Want's to provide a means for any File extension which I guess i critical.
But providing a way to allow file extensions that have a valid use case should be possible
Comment #5
spuky CreditAttribution: spuky as a volunteer commentedwould be nice If some of you could look over this...
also maybe provide hints how and which test would need to be written.
Comment #6
larowlanThanks, this is a feature request in my opinion.
In terms of testing, there should be an existing test case you can add to
Comment #7
spuky CreditAttribution: spuky as a volunteer commentedJust because it is checking wrong since merging file module into D7 10 years ago... does not mean it is not a Bug ;-)
but if it helps the Bug Smash Initiative Stats to declare that as "not a bug" I am fine with that
The Validator in Question is just used in the fieldSettingsForm function of the Field module.
So it is preventing me as a User of the UI from configuring / changing File extensions that are totally valid when Importing them via configuration management... oder using apis to set them.
I am struggling finding a testcase that covers the use of this form validator or the fieldSettingsForm of file module that I could attach to. Can anybody provide guidance where to put test... and what kind of tests
Comment #8
spuky CreditAttribution: spuky as a volunteer commentedComment #9
idebr CreditAttribution: idebr at iO commented#7 The classification for the category is explained in the issue handbook, see https://www.drupal.org/community/contributor-guide/reference-information...
Attached patch adds a test assertion a file extension containing an underscore can be configured through the user interface.
Comment #11
spuky CreditAttribution: spuky as a volunteer commentedThanks for the Test hope some People will be looking over this to get it towards RTBC
Comment #12
janmejaig CreditAttribution: janmejaig at Srijan | A Material+ Company for Drupal India Association commentedAfter applying the patch it is allowing to save the "_" (extension) , but while uploading the same it is giving an issue . This is giving an issue while uploading the file with "_" extension. This is not full filling the expectation , please look at the screen shot after applying the patch.
Comment #13
janmejaig CreditAttribution: janmejaig at Srijan | A Material+ Company for Drupal India Association commentedComment #14
naresh_bavaskar#9 LGTM and works fine for me for
FIle field
Testing steps
1) Added
x_t
extension in article content type and.FIle field saved succesfully.2) creating new node and uploaded "x_t" file into that file field and attached succesfully.
3) node saved successfully and again checked on edit page it remains attached file.
Just in checked patch that it has only functional test cases, not sure but might we should have more test cases on that.
@janmejaig I think you are trying to check _ (underscore) named extension in image field. but as per Issue summary this patch is allowing _ in file field.
Comment #15
janmejaig CreditAttribution: janmejaig at Srijan | A Material+ Company for Drupal India Association commentedI have recheck the above issue again and found that it is working fine for now . Please find the screen shot for the same .
Comment #17
spuky CreditAttribution: spuky as a volunteer commentedRerun patches from #9 against Drupal 9.2 and they are still valid... any more Input on this Issue by other People , what could be done better
Comment #19
paulocsSet back to RTBC because the failed test looks a random fail.
I run the test locally and did not find ant problem. See image attached.
Comment #20
jungleI think a CR is required, so tagging "Needs change record"
Comment #21
paulocsI'll provide it.
Comment #22
paulocsI just create a CR. It is simple one but I think it is enough to understand. Please have a look.
Comment #23
jungleThanks, @paulocs.
BTW, Made a few little changes to it:
Comment #24
jungleChanging the word File in title to use lowercase as well
Comment #26
jungleAn irrelevant random fail
Comment #27
alexpottThere's at least one other file type with _ in the apache mime type file -
application/vnd.denovo.fcselayout-link fe_launch
.I think the regex should be
^([a-z0-9]+([._][a-z0-9])* ?)+$
I.e. I don't think we should allow _ and the beginning or the end and like a dot I think we should only allow one of them.
Comment #28
anmolgoyal74 CreditAttribution: anmolgoyal74 at OpenSense Labs for DrupalFit commentedUpdated the regex as mentioned in #28
Tested with following extensions:
x_t, x.t, xt, x_y_t
- acceptedx_.t, x._t, xt_, x__t, _xt
- not acceptedComment #29
anmolgoyal74 CreditAttribution: anmolgoyal74 at OpenSense Labs for DrupalFit commentedComment #31
ranjith_kumar_k_u CreditAttribution: ranjith_kumar_k_u at Zyxware Technologies commentedThe last patch works fine .
Comment #32
quietone CreditAttribution: quietone as a volunteer commenteddrupalPostForm is deprectated.
Comment #33
sarvjeetsingh CreditAttribution: sarvjeetsingh as a volunteer and at QED42 for Drupal India Association commentedReplacing the deprecated drupalPostForm method with the combination of drupalGet and submitForm methods.
Comment #35
anmolgoyal74 CreditAttribution: anmolgoyal74 at OpenSense Labs for DrupalFit commentedFixed the failing test.
Comment #36
jungleI think the above should be tested in the test(s).
Comment #37
quietone CreditAttribution: quietone as a volunteer commentedI was thinking the same thing. Back to NW for #36
Comment #38
anmolgoyal74 CreditAttribution: anmolgoyal74 at OpenSense Labs for DrupalFit commentedComment #39
quietone CreditAttribution: quietone as a volunteer commentedSince we are changing these lines can we also change
t(
to$this->t
Also, I think the messages are confusing and don't give me any understanding of what is allowed and not allow, particularly regarding underscores. In the first one, what does 'or underscores' mean. Does that mean that more than one underscore after the dot is not allowed? Is one underscore OK? Is '__a' accepted? Then the second message mentions 'leading dots' where as the first message is 'leading dot'. Can there be multiple dots? On yet another read, it is the addition of 'or underscores' that is causing problems for me.
I would say just revert these changes but then this is allowing underscores but only in certain positions in the extension and not two consecutive underscores. How to tell that to the user?
Comment #40
anmolgoyal74 CreditAttribution: anmolgoyal74 at OpenSense Labs for DrupalFit commented@quietone Thanks for reviewing.
I knew this would come up. I look quite complex to explain all the possible values which can be added. Maybe we can show accepted and not accepted cases in the description or If you can provide eny other input.
Comment #41
quietone CreditAttribution: quietone as a volunteer commented@anmolgoyal74, Before I can think about the interface test I want to understand why there are limitations on the use of the underscore. Looking back I see it is from alexpott in #27.
Why? For example, what is the problem with this filename?
Comment #42
anmolgoyal74 CreditAttribution: anmolgoyal74 at OpenSense Labs for DrupalFit commented@quietone
I have followed the suggestions from @alexpott in #27.
In my opinion, there is no problem with
foo.___
, but that is not a known extension. you can create a file with any extension like that.I have the following document, I think we are good with the latest patch.
Check here https://en.wikipedia.org/wiki/List_of_file_formats.
Comment #43
quietone CreditAttribution: quietone as a volunteer commented@anmolgoyal74, thank you for the explanation. So, this just needs to have agreement on the user interface help text and to use $this->t.
So, the underscore is treated differently than [a-zA-z] and the dot. The file extensions can include underscores but not as the first or last character, multiple underscores are allowed in the extension but an underscore can not be followed by an underscore.
I am not good at user interface text and think this needs input from the UX folks. I considered setting to RTBC and having a follow up for the text but the text as it is now is confusing, at least to me, so I rejected that idea.
I have updated the IS and added some screenshots showing the changed text.
Comment #44
anmolgoyal74 CreditAttribution: anmolgoyal74 at OpenSense Labs for DrupalFit commentedChange t() to this->t().
And also tried to update the description.
Comment #46
anmolgoyal74 CreditAttribution: anmolgoyal74 at OpenSense Labs for DrupalFit commentedComment #48
anmolgoyal74 CreditAttribution: anmolgoyal74 at OpenSense Labs for DrupalFit commentedUpdated tests.
Comment #49
quietone CreditAttribution: quietone as a volunteer commentedI talked with benjifisher who suggested that this gets tagged, 'Needs usability review', and to post in #ux or in the agenda for the next Usability meeting. So adding tag and I'll do the others too.
Updated the IS with the latest text and screen shots, which required a patch reroll. :-(
Comment #50
quietone CreditAttribution: quietone as a volunteer commentedI got a message from jhodgson on #ux that the best way to get this reviewed at the ux meeting is for someone to show up and explain what is needed. The next meeting is Friday 15:00 UTC. I really don't want to attend because that is Sat 0400 for me. Can anyone here attend and get the interface text discussed?
Comment #51
benjifisherLooking at the patch from #49, the existing help text is
and the proposed help text is
If the validation fails, the original error message is
and the proposed error message is
I think having the text like this, as text, makes it easier to review than having it in a screenshot. That is especially true for people who are visually impaired.
Comment #52
benjifisherUsability review
We discussed this issue at #3194390: Drupal Usability Meeting 2021-01-29.
General rules for interface text include
Some of this is specified on Interface text. It does not mention "&" vs. "and", but I think it should.
Following these guidelines, we suggest the following for the help text:
In order to keep it short, we leave out the rule that '.' and '_' cannot appear next to each other. Although it is annoying to be surprised by such a rule after submitting the form, we want to keep the text short and it seems unlikely to come up.
The error message can be a little longer than the help text, and it should be more explicit. We suggest
I am setting the status to NW for the text changes and an update to the issue summary. Please add the text changes to the "Proposed resolution" section and update the screenshots in the "User interface changes" section.
Comment #53
anmolgoyal74 CreditAttribution: anmolgoyal74 at OpenSense Labs for DrupalFit commentedUpdated the text as per the proposed solution.
Comment #54
anmolgoyal74 CreditAttribution: anmolgoyal74 at OpenSense Labs for DrupalFit commentedComment #55
anmolgoyal74 CreditAttribution: anmolgoyal74 at OpenSense Labs for DrupalFit commentedComment #56
anmolgoyal74 CreditAttribution: anmolgoyal74 at OpenSense Labs for DrupalFit commentedComment #57
anmolgoyal74 CreditAttribution: anmolgoyal74 at OpenSense Labs for DrupalFit commentedComment #58
quietone CreditAttribution: quietone as a volunteer commented@benjifisher, thank you for the UX review. I hope to remember to show the strings in the future instead of screenshots.
#52. Added the string changes to the Proposed Resolution in the IS. The screen shots were updated in #55
I applied the patch and tested with valid and invalid field extensions, 'a.b', 'a..', 'a__'. With invalid options I found that the error message gave enough information so I could fix the problem. And the help text was clear and concise.
I then confirmed that the text changes exactly matched the suggested changes. (Probably should have done this first)
Both invalid and valid extensions are tested so I reckon this is ready.
@anmolgoyal74, thanks for your commitment to getting this in.
Comment #59
alexpottThis all looks really good. A recent fix has added testing of very similar functionality...
Let's part this part of \Drupal\Tests\file\Functional\FileFieldWidgetTest::testFileExtensionsSetting() as this is about configuring the file field and it test very similar functionality.
Comment #60
anmolgoyal74 CreditAttribution: anmolgoyal74 at OpenSense Labs for DrupalFit commentedMove the test from
+++ b/core/modules/file/tests/src/Functional/FileFieldValidateTest.php
to+++ b/core/modules/file/tests/src/Functional/FileFieldWidgetTest.php
.Comment #62
quietone CreditAttribution: quietone as a volunteer commentedYes, that makes the change requested in #59.
Comment #63
alexpottCommitted 663c57b and pushed to 9.2.x. Thanks!
Comment #65
jungleBTW, updated CR and published it.