OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Prevent recursive attribute macros
Oliver Günther9fcf13c96964
diff --git a/config/locales/js-en.yml b/config/locales/js-en.ymlindex 25ada1922c2..76d0b619abd 100644--- a/config/locales/js-en.yml+++ b/config/locales/js-en.yml@@ -172,6 +172,7 @@ en:attribute_reference:macro_help_tooltip: "This text segment is being dynamically rendered by a macro."not_found: "Requested resource could not be found"+ nested_macro: "This macro is recursively referencing %{model} %{id}."invalid_attribute: "The selected attribute '%{name}' does not exist."child_pages:button: "Links to child pages"diff --git a/frontend/src/app/shared/components/fields/macros/attribute-value-macro.component.ts b/frontend/src/app/shared/components/fields/macros/attribute-value-macro.component.tsindex a4028886715..30666027037 100644--- a/frontend/src/app/shared/components/fields/macros/attribute-value-macro.component.ts+++ b/frontend/src/app/shared/components/fields/macros/attribute-value-macro.component.ts@@ -51,6 +51,8 @@ import {import { firstValueFrom } from 'rxjs';import { ISchemaProxy } from 'core-app/features/hal/schemas/schema-proxy';+export const ATTRIBUTE_MACRO_CLASS = 'op-attribute-value-macro';+@Component({templateUrl: './attribute-value-macro.html',styleUrls: ['./attribute-macro.sass'],@@ -94,8 +96,20 @@ export class AttributeValueMacroComponent implements OnInit {const model = element.dataset.model as SupportedAttributeModels;const id = element.dataset.id as string;const attributeName = element.dataset.attribute as string;+ element.classList.add(ATTRIBUTE_MACRO_CLASS);++ if (this.isNestedMacro(model, id, attributeName)) {+ const error = this.I18n.t('js.editor.macro.attribute_reference.nested_macro', { model, id });+ this.markError(error);+ } else {+ void this.loadAndRender(model, id, attributeName);+ }+ }- void this.loadAndRender(model, id, attributeName);+ private isNestedMacro(model:SupportedAttributeModels, id:string, attributeName:string):boolean {+ const element = this.elementRef.nativeElement as HTMLElement;+ const parent = element.parentElement;+ return !!parent?.closest(`.${ATTRIBUTE_MACRO_CLASS}[data-model="${model}"][data-id="${id}"][data-attribute="${attributeName}"]`);}private async loadAndRender(model:SupportedAttributeModels, id:string, attributeName:string):Promise<void> {diff --git a/spec/features/wysiwyg/macros/attribute_macros_spec.rb b/spec/features/wysiwyg/macros/attribute_macros_spec.rbindex c85aadc7a0b..088ae194132 100644--- a/spec/features/wysiwyg/macros/attribute_macros_spec.rb+++ b/spec/features/wysiwyg/macros/attribute_macros_spec.rb@@ -186,4 +186,22 @@ RSpec.describe "Wysiwyg attribute macros", :js doendendend++ describe "recursively referencing descriptions (Regression #55320)" do+ let(:wp_page) { Pages::FullWorkPackage.new(work_package) }++ before do+ work_package.update_column(:description, "Hello from wp workPackageValue:##{milestone.id}:description")+ milestone.update_column(:description, "Hello from milestone workPackageValue:##{work_package.id}:description")+ end++ it "does not runaway" do+ wp_page.visit!++ expect(page).to have_text("Hello from wp")+ expect(page).to have_text("Hello from milestone")++ expect(page).to have_text("This macro is recursively referencing workPackage ##{milestone.id}")+ end+ endend