diff --git a/__tests__/__image_snapshots__/html/adaptive-cards-parser-max-version-js-adaptive-cards-with-adaptive-cards-parser-max-version-style-options-1-snap.png b/__tests__/__image_snapshots__/html/adaptive-cards-parser-max-version-js-adaptive-cards-with-adaptive-cards-parser-max-version-style-options-1-snap.png new file mode 100644 index 0000000000..2b4d152130 Binary files /dev/null and b/__tests__/__image_snapshots__/html/adaptive-cards-parser-max-version-js-adaptive-cards-with-adaptive-cards-parser-max-version-style-options-1-snap.png differ diff --git a/__tests__/__image_snapshots__/html/adaptive-cards-parser-max-version-js-adaptive-cards-with-adaptive-cards-parser-max-version-style-options-2-snap.png b/__tests__/__image_snapshots__/html/adaptive-cards-parser-max-version-js-adaptive-cards-with-adaptive-cards-parser-max-version-style-options-2-snap.png new file mode 100644 index 0000000000..a880536729 Binary files /dev/null and b/__tests__/__image_snapshots__/html/adaptive-cards-parser-max-version-js-adaptive-cards-with-adaptive-cards-parser-max-version-style-options-2-snap.png differ diff --git a/__tests__/__image_snapshots__/html/adaptive-cards-parser-max-version-js-adaptive-cards-with-adaptive-cards-parser-max-version-style-options-3-snap.png b/__tests__/__image_snapshots__/html/adaptive-cards-parser-max-version-js-adaptive-cards-with-adaptive-cards-parser-max-version-style-options-3-snap.png new file mode 100644 index 0000000000..2b4d152130 Binary files /dev/null and b/__tests__/__image_snapshots__/html/adaptive-cards-parser-max-version-js-adaptive-cards-with-adaptive-cards-parser-max-version-style-options-3-snap.png differ diff --git a/__tests__/html/adaptiveCards.parserMaxVersion.html b/__tests__/html/adaptiveCards.parserMaxVersion.html new file mode 100644 index 0000000000..6fce4a8c9d --- /dev/null +++ b/__tests__/html/adaptiveCards.parserMaxVersion.html @@ -0,0 +1,96 @@ + + +
+ + + + + + + + diff --git a/__tests__/html/adaptiveCards.parserMaxVersion.js b/__tests__/html/adaptiveCards.parserMaxVersion.js new file mode 100644 index 0000000000..710d2658b5 --- /dev/null +++ b/__tests__/html/adaptiveCards.parserMaxVersion.js @@ -0,0 +1,8 @@ +/** + * @jest-environment ./__tests__/html/__jest__/WebChatEnvironment.js + */ + +describe('Adaptive Cards', () => { + test('with "adaptiveCardsParserMaxVersion" style options', () => + runHTMLTest('adaptiveCards.parserMaxVersion.html')); +}); diff --git a/packages/bundle/src/adaptiveCards/hooks/internal/useParseAdaptiveCardJSON.js b/packages/bundle/src/adaptiveCards/hooks/internal/useParseAdaptiveCardJSON.js index 4627e20c7b..a493baa654 100644 --- a/packages/bundle/src/adaptiveCards/hooks/internal/useParseAdaptiveCardJSON.js +++ b/packages/bundle/src/adaptiveCards/hooks/internal/useParseAdaptiveCardJSON.js @@ -1,9 +1,9 @@ import { hooks } from 'botframework-webchat-component'; -import { useCallback } from 'react'; +import { useCallback, useMemo } from 'react'; import useAdaptiveCardsPackage from '../useAdaptiveCardsPackage'; -const { useDirection } = hooks; +const { useDirection, useStyleOptions } = hooks; function updateRTLInline(element, rtl, adaptiveCardsPackage) { if (element instanceof adaptiveCardsPackage.Container) { @@ -25,8 +25,19 @@ function updateRTLInline(element, rtl, adaptiveCardsPackage) { export default function useParseAdaptiveCardJSON() { const [adaptiveCardsPackage] = useAdaptiveCardsPackage(); const [direction] = useDirection(); + const [{ adaptiveCardsParserMaxVersion }] = useStyleOptions(); - const { AdaptiveCard, SerializationContext } = adaptiveCardsPackage; + const { AdaptiveCard, SerializationContext, Version } = adaptiveCardsPackage; + + const maxVersion = useMemo(() => { + const maxVersion = Version.parse(adaptiveCardsParserMaxVersion, new SerializationContext()); + + if (maxVersion && !maxVersion.isValid) { + return console.warn('botframework-webchat: "adaptiveCardsParserMaxVersion" specified is not a valid version.'); + } + + return maxVersion; + }, [adaptiveCardsParserMaxVersion]); return useCallback( (content, { ignoreErrors = false } = {}) => { @@ -36,7 +47,7 @@ export default function useParseAdaptiveCardJSON() { const card = new AdaptiveCard(); const errors = []; - const serializationContext = new SerializationContext(); + const serializationContext = new SerializationContext(maxVersion); card.parse(content, serializationContext); @@ -56,6 +67,6 @@ export default function useParseAdaptiveCardJSON() { return card; }, - [AdaptiveCard, adaptiveCardsPackage, direction, SerializationContext] + [AdaptiveCard, adaptiveCardsPackage, direction, maxVersion, SerializationContext] ); }