Problem/Motivation
Steps to reproduce:
1. Add new content type at /admin/structure/types/add
2. Make sure some options are selected under "Publishing options"
Actual result:
Summary shows:
"Published , Promoted to front page , Create new revision"
See https://www.drupal.org/files/issues/comma-before-space-bug.png
Expected result:
Summary shows:
"Published, Promoted to front page, Create new revision"
See https://www.drupal.org/files/issues/comma-before-space.png
Proposed resolution
Strip unwanted whitespace before commas
Remaining tasks
- Add JS testing
- Review Patch
User interface changes
- Stripped unwanted commas
API changes
None.
Data model changes
None.
Comment | File | Size | Author |
---|---|---|---|
#78 | 2849100-75-test-only.patch | 1.81 KB | adriancid |
#78 | 2849100-75.patch | 2.44 KB | adriancid |
#62 | After applying patch - Space before commas.jpg | 78.5 KB | NikitaJain |
#62 | After applying patch - Space commas 2.jpg | 63.5 KB | NikitaJain |
#62 | After applying patch - Space commas 3.jpg | 59.28 KB | NikitaJain |
Comments
Comment #2
hugovk CreditAttribution: hugovk at Digia commentedHere's a patch against 8.4.x.
Cause:
core/modules/node/content_types.js is comma joining an array that contains newlines and whitespace:
["↵ ↵↵ Published↵ ", "↵ ↵↵ Promoted to front page↵ ", "↵ ↵↵ Create new revision↵ "]
Fix:
Trim the values before joining:
["Published", "Promoted to front page", "Create new revision"]
See patch or https://github.com/hugovk/drupal/compare/8.4.x...hugovk:8.4.x-no-space-b...
The patch doesn't trim before the other
return vals.join(', ');
lines in the same file, as it doesn't look like there are multiple values to be shown. But it may be a good idea to include the fix there too.Comment #3
hugovk CreditAttribution: hugovk at Digia commentedComment #4
hugovk CreditAttribution: hugovk at Digia commentedComment #5
hugovk CreditAttribution: hugovk at Digia commentedComment #6
hugovk CreditAttribution: hugovk at Digia commentedNote: this problem doesn't occur for "Language settings".
Comment #7
cilefen CreditAttribution: cilefen commentedComment #8
wturrell CreditAttribution: wturrell as a volunteer commented- I've updated issue summary template
- able to reproduce original problem
- successfully fixed by patch
- the javascript looks absolutely fine and no errors in JS console
- shouldn't require browser testing
- have tried various combinations of settings in all vertical tabs, no regressions
- patch is in scope
- comment makes sense
- no string changes
P.S. should this be moved from 8.4.x to 8.3.x as it's a bug fix?
Comment #9
Anonymous (not verified) CreditAttribution: Anonymous commented#2 this trick looks nice. But why do we need it? Because we have the
["↵ ↵↵ Published↵ ", "↵ ↵↵ Promoted to front page↵ ", "↵ ↵↵ Create new revision↵ "]
? But why do we have this result? Because we collect values asBut why do we do this way? It was appear here. But after we have next change (here):
Can we use this approach here?
Also we have several different code in one small file:
Maybe try to bring to a common code mean?
Comment #10
Anonymous (not verified) CreditAttribution: Anonymous commentedthis is what I meant in the local and global scope
Comment #11
hugovk CreditAttribution: hugovk at Digia commentedI had a quick test of those two patches in Drupal 8.2.5 and they both worked.
Comment #12
Dinesh18 CreditAttribution: Dinesh18 as a volunteer commentedI have tested both the patch and it is working as expected.
Comment #13
th_tushar CreditAttribution: th_tushar as a volunteer commentedLooks like RTBC!
Comment #14
xjmThanks for your contributions on this!
@wturrell, thanks for the step-by-step documentation of your review!
@Dinesh18, to receive credit for your review and testing, please document how you documented the patch and what is working as expected. Simply saying it is "working as expected" does not confirm any fix and does not help the issue get in. One way to demonstrate your testing would be to post before screenshots (without the patch) and after screenshots (with the patch). Also write out what you did to test it.
For this issue, we should also be able to add JavaScript tests to prove the fix I think.
There are two patches attached in #10. One of them is a one-line fix, and the other seems like way too much code to change for extra spaces. Let's pick one and document why in the IS. Maybe a JS maintainer can give feedback and confirm the correct fix. Tagging as a JS issue also so JS maintainers can find the issue if they like.
Finally, I believe there is a duplicate of this issue somewhere in the queue, possibly from many years ago. Can someone search and try to find duplicate issues in the queue to see what other work might be in progress or already fixed?
Thanks everyone!
Comment #15
droplet CreditAttribution: droplet commented- one line patch looks fine to me.
- I didn't align it line-by-line. The huge patch looks like a refactoring rather than bug fixing. It should split into a new issue. Thanks.
Addition:
- It should be only ONE "#edit-title-label". No join is required
Comment #16
Anonymous (not verified) CreditAttribution: Anonymous commentedI'll do the JS test now.
Comment #17
Anonymous (not verified) CreditAttribution: Anonymous commentedI'm sorry for the delay. The patch checks the appearance of labels and separated by commas. But not testing this:
We need testing it?
Looks like a refactoring too, no?
Comment #18
Anonymous (not verified) CreditAttribution: Anonymous commentedOnly one found by search "space|spaces|comma|commas" in "javascript|node system".
Comment #20
hugovk CreditAttribution: hugovk at Digia commentedThank you vaplas!
So this bug has been around since at least Drupal 7 and 2010 (!) when it was reported in https://www.drupal.org/node/991522. That was then closed as a duplicate of another, but that other one was committed in 2014 and didn't fix this problem, and then was reopened 10 months ago and has sat dormant since.
It'd be great if we could get one of these patches in for D8 and then consider it for D7 too :) What's needed for that?
Comment #21
Dinesh18 CreditAttribution: Dinesh18 as a volunteer commented@xjm : I have applied the patch mentioned in #10. Here are the screengrab requested before and after the patch.
PFA
1) Edit Article content type Drupal8_after patch applied.png
2) Edit Article content type Drupal8_ before applying the patch.png
Comment #22
chiranjeeb2410 CreditAttribution: chiranjeeb2410 commentedJS test patch applies cleanly. Changes are good to go with. Changing to RTBC.
Comment #23
xjmGreat work on the screenshots and adding JS tests! We might need to make some small additional improvements to the patch. Hopefully I or another committer can follow up about that soon. I just wanted to say though that it's great to see the progress here in the meanwhile.
Thanks also to @chiranjeeb2410. Just a note, in the future, be sure to specify once you tested and the reasons that you concluded that a patch is ready to go. Thank you for reviewing the JavaScript change!
Comment #24
Anonymous (not verified) CreditAttribution: Anonymous commentedThanks for reviews! Unfortunately, my patch looks bit doubtful. Therefore, we need to stay on the NR. For example:
private or protected or not use additional functions?
Attached patch testing only commas, but it is not equivalent too :(
Comment #25
chiranjeeb2410 CreditAttribution: chiranjeeb2410 commented@xjm,
Thanks for the update. Would keep that in mind.
Comment #26
chiranjeeb2410 CreditAttribution: chiranjeeb2410 commented@xjm,
Thanks for the update. Would keep that in mind.
Comment #28
xjmSetting back to NR as suggested by @vaplas in #24, for review of the updated patch. Thanks!
Comment #29
Anonymous (not verified) CreditAttribution: Anonymous commentedBit improvement, now test more clearly.
Comment #30
droplet CreditAttribution: droplet commented"protected", allowed to override :)
If you could, a standard testing for SUMMARY text updates would be great! BUT for this issue, we only need test commas.
A standard test, for example, clicking 2 options in Publishing Options:
expected string: "Published, Promoted to front page"
(this is also testing commas)
Comment #32
Anonymous (not verified) CreditAttribution: Anonymous commented@droplet, thanks for help with my questions! I can add needs tests without problem. Which procedure is best for this?
Right?
I would also add a couple of thoughts to the #29 patch.
$page->findAll('css', '.vertical-tabs__menu')[0]->getText();
It looks rude, because captures all region with tabs like one text. But this is also its advantage as prevent regression in the case with adding new tab. Also we cann't testing only one tab, because content_types.js implements a collection of elements for each tab by different code.
But maybe we can simplify this test after refactoring of js.
Comment #33
droplet CreditAttribution: droplet commentedMaybe:
- Fix this, write a test for Publishing
- Full test cover of content_types.js (we can do it together, just clone it 4 times, nothing more)
- Refactoring content_types.js
I'd suggested just to test what we have now.
1. Perform a click to cancel one default setting.
2. Compare expected result to
jQuery('[href="#edit-workflow"]').find('.vertical-tabs__menu-item-summary').text()
Tests should not affect by a simple refactoring like Patch #10.
Comment #34
Anonymous (not verified) CreditAttribution: Anonymous commentedComment #36
droplet CreditAttribution: droplet commentedcan we uncheck one or also check Sticky, because these 2 are default option. (even the script is broken, we will see correct Summary Text)
We don't need this check I think, or merged with code below as condition.
Comment #37
wturrell CreditAttribution: wturrell as a volunteer commentedI've just reviewed this again too…
- still able to reproduce original problem
- still fixed by patch
- still no JS errors
- coding style of the test looks perfect, no errors
- note: the waitFor time is in milliseconds
- as @droplet says, we've only got one test combination here. That doesn't bother me especially, but you could try turning Published off (which'll change it to "Not published") and maybe enable "Sticky" and disable "Create new revision" or something - i.e. do it in such a way it's had to change the entire sentence. And actually, if you're going to do that, might as well do another test with them all unchecked and make sure there are no commas…
+1 for RTBC from me though otherwise…
Comment #38
Anonymous (not verified) CreditAttribution: Anonymous commented@droplet, @wturrell thanks for reviews!
I like idea about 'uncheck status' and testing 'Not published', but we cann't do only it, because it set manual (without right space). Hence comma between "Not published" and "Promoted to front page" will correct always:
Also we need waiting after check()/uncheck(), because the script does not always have time to execute. We can wrapping
wait
byassertTrue
, but the error message is not very informative:false is not true
(see all_patch).If content_type.js not run, we have empty Summary Text. Or I misunderstood this phrase? Therefore, can we rely on the default settings and check the script immediately (see mini_patch)?
Bit clean-up in mini_patch:
Because we not testing "Language settings" now. (edit: opps, i'm do it for all patch, but not mini patch)
public function find($selector, $locator)
,findAll(...)[0]
to justfind(...)
.What about names and comments:
Comment #41
Truptti CreditAttribution: Truptti at Axelerant commentedVerified the patch 'mini_2849100-38.patch' in #38 on Drupal 8.4.x site, below are the observations
1.Before applying the patch space was displayed before comma on Publising options
2.After applying patch 'mini_2849100-38.patch' on Drupal 8.4.x, the patch applied smoothly and the space before comma at Publishing options is removed. Attaching snapshot beforepatch.png and afterpatch.png for reference.
This can be marked as RTBC.
Comment #42
droplet CreditAttribution: droplet commented@vaplas,
You are right.
I preferred all.patch, even the error almost never happen in Drupal Core :) But I think tests are designed for unexpected. We able to make the script does not work after the first execution.
what if drop the waitFor also?
\#
, escape? is it required?href="#edit-workflow", please :)
Comment #43
droplet CreditAttribution: droplet commentedComment #44
Anonymous (not verified) CreditAttribution: Anonymous commentedThanks for hint!
This code works:
But this code not works:
Comment #47
Anonymous (not verified) CreditAttribution: Anonymous commentedStrangely. Trick from 2849100-44.patch works on my machine. In any case, I think it only further confirms the need to wait the script.
Comment #48
droplet CreditAttribution: droplet commentedSorry @vaplas, I thought that works...So to prevent random failure. Let's keep waitFor.
Comment #49
tameeshb CreditAttribution: tameeshb at Google Summer of Code commentedThe test fail looks like it was expecting a string :
'Not published, Promoted to front page, Sticky at top of lists, Create new revision'
But the output text was:
'Published, Promoted to front page, Create new revision'
So I changed the test file to check for the latter text.
Comment #50
Anonymous (not verified) CreditAttribution: Anonymous commented@tameeshb, after unchecked
status
and checkedsticky
we are entitled to demand'Not published, Promoted to front page, Sticky at top of lists, Create new revision'
Comment #51
droplet CreditAttribution: droplet commentedComment #52
Anonymous (not verified) CreditAttribution: Anonymous commentedwhich variant is better?
Comment #55
hugovk CreditAttribution: hugovk at Digia commenteddroplet, tameeshb: any comments on vaplas's latest patches?
Comment #56
NikitaJain CreditAttribution: NikitaJain commentedVerified the patch '2849100-51.patch' in #52 on Drupal 8.4.x version.
- Able to reproduce the issue before applying the patch.
- Patch applied successfully without any errors.
- Before applying the patch:
a) The space was appearing before commas for all publishing options (Published, Promoted to front page, Sticky at top of lists, Create new revision).
b) For 'Not published' status, the space was not there before commas. So in this case the issue is already resolved.
- After applying the patch:
a) The space before comma has been removed for all other publishing options (Published, Promoted to front page, Sticky at top of lists, Create new revision).
b) Also after unchecked status and checked sticky its working fine
(Not published, Promoted to front page, Sticky at top of lists, Create new revision)
c) The above patch works fine in all other conditions.
Screen-shots attached
Comment #57
lauriiiShould we add a class for the label so to allow overriding the label with another element. This also documents the dependency from JS to this element.
The vertical tab should be called 'Publishing options'
Comment #58
gaurav.kapoor CreditAttribution: gaurav.kapoor at OpenSense Labs commentedComment #59
gaurav.kapoor CreditAttribution: gaurav.kapoor at OpenSense Labs commentedComment #60
gaurav.kapoor CreditAttribution: gaurav.kapoor at OpenSense Labs commentedComment #61
Anonymous (not verified) CreditAttribution: Anonymous commentedI'm sorry for the delay.
#55: @hugovk thank you for good question!)
#56: @NikitaJain thank you for detailed review!
#57: @lauriii thank you for review and good ideas!
#59: @gaurav.kapoor thank you for help with 57.2!
added 57.1 point.
Comment #62
NikitaJain CreditAttribution: NikitaJain commentedVerified the patch '2849100-61.patch' in #61 on Drupal 8.4.x version.
- Able to reproduce the issue before applying the patch.
- Patch applied successfully without any errors.
- Before applying the patch:
- The space was appearing before commas for all publishing options (Published, Promoted to front page, Sticky at top of lists, Create new revision).
- After applying the patch:
a) The space before commas has been removed for all other publishing options (Published, Promoted to front page, Sticky at top of lists, Create new revision).
b) Checked for all other conditions, its working fine.
Screen-shots attached
Comment #63
Anonymous (not verified) CreditAttribution: Anonymous commented@NikitaJain, thank you for nice user review again! But I think we should wait for the code review too.
For example, I added a class
'.js-option__label'
. And__
(double underline) is used in the css for the child pointer. Butlabel
is not child ofinput
. Hence, maybe better use'-'
. Added patch with it (repeated user review for this patch is not necessary, only the code).Comment #64
Anonymous (not verified) CreditAttribution: Anonymous commentedopps, #63 contains correct interdiff, but old patch. New patch here.
Comment #65
droplet CreditAttribution: droplet commentedBeing more complicated over time. If committers agreed, we should fix them all with other vtabs in a new refactoring.
Comment #66
lauriiiI discussed with @nod_ and we agreed that even though core has plenty of js- prefixed classes, all additions should be done using data attributes. So instead of what I proposed on #57.1, we should use data attributes as a selector when using JS since that is even less likely to be messed up by anyone. Sorry for giving slightly off directions earlier :)
Comment #67
Anonymous (not verified) CreditAttribution: Anonymous commented@droplet, yeah. You know, I was offered a just check the entire
'.vertical-tabs__menu'
region (#29) and gohometo full refactoring issue :)@lauriii, no problem.
Tag
input
already havedata-drupal-selector
with'edit-options-*'
values. Which is better to choose for thelabel
:Which selector is best:
input[data...
or just[data....
Comment #68
droplet CreditAttribution: droplet commentedthere's a way to guard the accessibility also. use [for] attr.
If we do #67 way, IMO, we should not use jQuery next that allowed more freedom custom coding.
Comment #69
hugovk CreditAttribution: hugovk at Digia commentedYep, nearly 70 comments! So where are we up to? It'd be great to get something merged and fix this 7-year-old bug, and create a new issue is further refactoring is still warranted.
Thanks everyone for all your work so far on this!
Comment #70
Anonymous (not verified) CreditAttribution: Anonymous commentedI tried to create an issue about refactoring and move everything I know about this. See #2871619: Refactoring content_type.js.
Comment #71
tstoecklerMarked #2871214: Remove a space in the Publishing options vertical tab as duplicate as the patch there did not have test coverage. The fix over there seemed to go in a slightly different direction maybe someone from there can comment here.
Comment #72
droplet CreditAttribution: droplet commentedPatch like #51 is good enough at the moment and really fit into this issue scope.
Comment #73
Anonymous (not verified) CreditAttribution: Anonymous commented@droplet: you mean #50 or #52?)
Comment #74
hugovk CreditAttribution: hugovk at Digia commentedThere is no patch in #51, but I assume @droplet meant #52 which has been reviewed, so putting this back into RTBC :)
Comment #75
Anonymous (not verified) CreditAttribution: Anonymous commented#74 +1.
Re-upload #52, because afaik the RTBC status should apply to the last patch.
Edit: Opps, looks like @droplet really pointed to #52. The fact is that I just incorrectly addd postfix to this patch, hence a small confusion, sorry!
Comment #76
Anonymous (not verified) CreditAttribution: Anonymous commentedChanged the status to run tests. Also all points from @droplet and @lauriii have big sense, but this is really bit out of scope from issue about annoying space. Welcome to the #2871619: Refactoring content_type.js, or we need change title and summary here, so as not to mislead anyone :)
Comment #77
droplet CreditAttribution: droplet commentedThanks, @hugovk & @vaplas.
the latest patch #75 is fine.
Comment #78
adriancidSame patch but with the correct extension.
Comment #80
Anonymous (not verified) CreditAttribution: Anonymous commentedrandom fail.
Comment #81
hugovk CreditAttribution: hugovk at Digia commentedLooks good:
Comment #85
lauriiiAfter reconsideration and @droplet pointing out that this can be used to safeguard accessibility, I think it makes sense to target the label element directly.
Thank you for adding the JavaScript test coverage.
Committed e31abcc and pushed to 8.4.x. Thanks!
I wouldn't backport this to 8.3.x because this has a minor change in how the text in summary is built.
Comment #87
lauriiiComment #88
hugovk CreditAttribution: hugovk at Digia commentedThanks everyone who helped out, this was my first ever Drupal core bug report!
Comment #89
droplet CreditAttribution: droplet commentedThanks @hugovk. Do you enjoy it? haha
Now, we able move to the follow-up issue
Comment #90
hugovk CreditAttribution: hugovk at Digia commented@droplet Yes, it's great to contribute, but I must say I'm looking forward to the change to something modern like GitHub or GitLab :) Creating/viewing/applying/re-rolling patches is somewhat tedious.
By the way, I think https://www.drupal.org/node/991522 can now be closed or marked as duplicate of this one. I can't edit it, please could someone check it? Thanks!
Comment #92
Anonymous (not verified) CreditAttribution: Anonymous commentedStill facing same problem in my D8.3 website. Any other way then to update drupal version. Patch also doesn't work for D8.3 ?