Problem/Motivation
When a child theme is updated to 2.0.x, bs_base_bs_update_200001() converts the variables of its theme-options.yml to Sass with _bs_base_yaml_variables_to_sass() in bs_base.bs_base.install (the theme-options.yml feature was removed in #3474790). The conversion has two bugs:
- Odd indent closes a map too early. The function computes the nesting depth as
($indent - $variablesIndent) / 2. When the entries of a nested map are indented with an odd number of spaces (one space less than the next level), the depth is a fraction, the open map is closed before its entries, and the entries land one level up. PHP also logs "Implicit conversion from float 1.5 to int". - A Sass variable used as a map key keeps its YAML quotes. Values have their outer YAML quotes stripped, but keys do not. A key such as
'$responsive-break'is written as the quoted string'$responsive-break', so it never matches the breakpoint and the value does not override the base theme's default.
Both produce valid Sass, so the theme compiles without an error and the bug only shows on the page: in our case the logo lost its vertical margin on phones, and the logo area was 350px instead of 150px wide at the md breakpoint.
Steps to reproduce
- In a 1.x child theme, have this in
theme-options.yml(the entries underxsare indented 9 spaces, those undermd10):
sass: injectVariables: variables: navbar-brand-vertical-margins: xs: top: '$spacer/2' bottom: '$spacer/2' md: top: '$spacer' bottom: '$spacer' navbar-brand-responsive-widths: xs: '160px' '$responsive-break': '150px' lg: '200px' - Update the theme to bs_base 2.0.x and run
drush bs-tu <theme> -y, which runsbs_base_bs_update_200001(). - Read the generated Sass variables. Actual output:
$navbar-brand-vertical-margins: ( xs: ( ), top: $spacer/2, bottom: $spacer/2, md: ( top: $spacer, bottom: $spacer, ), ); $navbar-brand-responsive-widths: ( xs: 160px, '$responsive-break': 150px, lg: 200px, );Expected output:
$navbar-brand-vertical-margins: ( xs: ( top: $spacer/2, bottom: $spacer/2, ), md: ( top: $spacer, bottom: $spacer, ), ); $navbar-brand-responsive-widths: ( xs: 160px, $responsive-break: 150px, lg: 200px, );
Proposed resolution
- Keep the indent of each open map on the stack instead of computing the depth from the indent. A line closes every open map that is indented as much as the line or more, and the depth is the number of maps still open. This nests odd indents correctly and removes the float notice.
- Strip one layer of YAML quotes from a key in the key-value branch, the same way values are stripped.
Remaining tasks
- Review the merge request.
User interface changes
None.
API changes
None.
Data model changes
None.
Issue fork bs_base-3644426
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
pivica commented