Skip to content

fix(style): resolve uncorrect remove style regex - #225

Merged
farnabaz merged 2 commits into
nuxt-community:masterfrom
potato4d:fix/remove-style-regex
Jan 10, 2021
Merged

fix(style): resolve uncorrect remove style regex#225
farnabaz merged 2 commits into
nuxt-community:masterfrom
potato4d:fix/remove-style-regex

Conversation

@potato4d

@potato4d potato4d commented Jan 2, 2021

Copy link
Copy Markdown
Member

This pull-request resolves </style><style> pattern regex problem.

Example

as-is

// in: '<style>a {}</style><style>b {}</style><style>c {}</style><style>'
// out: '<style>a {}'

(() => {
  const params = { HEAD: '<style>a {}</style><style>b {}</style><style>c {}</style><style>' }
  return params.HEAD.replace(/<\/style>[\S\s]*<style[^>]*>/g, '')
})()

to-be

// in: '<style>a {}</style><style>b {}</style><style>c {}</style><style>'
// out: `<style>a {}
// b {}
// c {}</style>`

(() => {
  const params = { HEAD: '<style>a {}</style><style>b {}</style><style>c {}</style><style>' }

  const styleRegex = /<style(?: .+?)?>([\s\S]*?)<\/style>/g
    const styleList = params.HEAD.match(styleRegex).map((css) => {
      const rawStyle = css.replace(styleRegex, '$1')
      return rawStyle
    })
    return params.HEAD.replace(styleRegex, '') + `${styleList.join('\n')}</style>`
})()

@codecov

codecov Bot commented Jan 2, 2021

Copy link
Copy Markdown

Codecov Report

Merging #225 (3cf5d8d) into master (f3bbea6) will decrease coverage by 2.00%.
The diff coverage is 0.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #225      +/-   ##
==========================================
- Coverage   69.02%   67.02%   -2.01%     
==========================================
  Files           5        5              
  Lines         184      188       +4     
  Branches       52       52              
==========================================
- Hits          127      126       -1     
- Misses         41       46       +5     
  Partials       16       16              
Impacted Files Coverage Δ
lib/module.js 65.59% <0.00%> (-4.08%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f3bbea6...3cf5d8d. Read the comment docs.

@potato4d

potato4d commented Jan 3, 2021

Copy link
Copy Markdown
Member Author

@farnabaz
Currently, there is no test for removeInlineStyle, how should it be added?

@farnabaz farnabaz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank You

@farnabaz

Copy link
Copy Markdown
Member

@potato4d We can create a separate test for it by disabling extractCSS

beforeAll(async () => {
  const port = await getPort({ port: getPort.makeRange(3000, 3100) })
  url = path => `http://localhost:${port}${path}`
  const config = {
    ...defaultConfig,
    buildDir: '.nuxt/test.styles',
    dev: false,
    build: {
       extractCSS: false
    },
  }
  nuxt = new Nuxt(config)
  await nuxt.ready()
  await new Builder(nuxt).build()
  return await nuxt.listen(port)
})

I'll merge this PR and release v0.5.3. You are more than welcome to create another PR for tests ❤️

@farnabaz
farnabaz merged commit d995b23 into nuxt-community:master Jan 10, 2021
@farnabaz farnabaz mentioned this pull request Jan 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants