Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

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

Merged
merged 2 commits into from
Jan 10, 2021
Merged

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

merged 2 commits into from
Jan 10, 2021

Conversation

potato4d
Copy link
Member

@potato4d potato4d commented Jan 2, 2021

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
Copy link

codecov bot commented Jan 2, 2021

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
Copy link
Member Author

potato4d commented Jan 3, 2021

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

Copy link
Member

@farnabaz farnabaz left a comment

Choose a reason for hiding this comment

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

Thank You

Copy link
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
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants