Skip to content

Conversation

@rotdrop
Copy link
Contributor

@rotdrop rotdrop commented Jun 28, 2025

Vue files can contain multiple (2, to be exact) script sections, one for setup, composition API, and one "ordinary" script section for the options API. At least fro Vue 2 both are at least wanted and maybe even needed and even with Vue 3 this is legal, see
https://vuejs.org/api/sfc-spec.html

This commit changes f5562bf and uses preg_match_all() with a look-ahead pattern in order to capture all script blocks.

Fixes #799.

In order to test the regexp pattern consider the following simple example:

<?php

$vueSource = '<script setup>
  SETUP_BLOCK
</script>
<script>
  NON-SETUP BLOCK
</script>';

$matches = [];
preg_match_all('/<script[^>]*>(.+(?=<\/script>))<\/script>/sU', $vueSource, $matches, PREG_PATTERN_ORDER);

print_r($matches);

echo implode('', $matches[1]) . PHP_EOL;

@rotdrop rotdrop force-pushed the bugfix/support-script-and-script-setup-together-in-vue-files branch from a47a561 to acf022f Compare June 28, 2025 18:31
@rotdrop
Copy link
Contributor Author

rotdrop commented Jun 28, 2025

Oops. The regexp pattern could be improved. Only one would be needed the lookahead or the non-greedy standard pattern ... so the following just will do:

preg_match_all('/<script[^>]*>(.+)<\/script>/sU', $vueSource, $matches, PREG_PATTERN_ORDER);

…m parser".

Vue files can contain multiple (2, to be exact) script sections, one for
setup, composition API, and one "ordinary" script section for the
options API. At least fro Vue 2 both are at least wanted and maybe even
needed and even with Vue 3 this is legal, see
https://vuejs.org/api/sfc-spec.html

This commit changes f5562bf and uses preg_match_all() with a non-greedy
pattern in order to capture all script blocks.

Fixes nextcloud#799.

Signed-off-by: Claus-Justus Heine <[email protected]>

WIP
@rotdrop rotdrop force-pushed the bugfix/support-script-and-script-setup-together-in-vue-files branch from acf022f to 44f61c5 Compare June 28, 2025 18:37
@rotdrop rotdrop requested review from nickvergessen and susnux June 28, 2025 18:38
@nickvergessen
Copy link
Member

There are tests files, can you adjust them to show the problem and fix?

Signed-off-by: Claus-Justus Heine <[email protected]>
@rotdrop rotdrop force-pushed the bugfix/support-script-and-script-setup-together-in-vue-files branch from 4ce07aa to 521279d Compare June 28, 2025 19:28
@rotdrop
Copy link
Contributor Author

rotdrop commented Jun 28, 2025

There are tests files, can you adjust them to show the problem and fix?

Yes, I'll add one with two script sections.

Signed-off-by: Claus-Justus Heine <[email protected]>
Signed-off-by: Joas Schilling <[email protected]>
@nickvergessen nickvergessen merged commit b7b49cf into nextcloud:master Jun 30, 2025
3 checks passed
@rotdrop rotdrop deleted the bugfix/support-script-and-script-setup-together-in-vue-files branch June 30, 2025 06:30
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.

Translationtool does not correctly handle <script setup> together with <script> in Vue-files

2 participants