Skip to content
This repository has been archived by the owner on Jan 29, 2024. It is now read-only.

Commit

Permalink
fix(service): fix .instant() not handling TrustedValueHolderType corr…
Browse files Browse the repository at this point in the history
…ectly

Although we have to reconsider the result type of this, this will fix sce+linking.

Fixes #1618
Replaces #1630
  • Loading branch information
knalli committed Oct 30, 2016
1 parent aaaa972 commit 1ede55e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/service/translate.js
Original file line number Diff line number Diff line change
Expand Up @@ -1401,7 +1401,13 @@ function $translate($STORAGE_KEY, $windowProvider, $translateSanitizationProvide
Interpolator.setLocale(langKey);
result = Interpolator.interpolate(translationTable[translationId], interpolateParams, 'filter', sanitizeStrategy);
result = applyPostProcessing(translationId, translationTable[translationId], result, interpolateParams, langKey, sanitizeStrategy);
if (result.substr(0, 2) === '@:') {
// workaround for TrustedValueHolderType
if (!angular.isString(result) && angular.isFunction(result.$$unwrapTrustedValue)) {
var result2 = result.$$unwrapTrustedValue();
if (result2.substr(0, 2) === '@:') {
return getFallbackTranslationInstant(langKey, result2.substr(2), interpolateParams, Interpolator, sanitizeStrategy);
}
} else if (result.substr(0, 2) === '@:') {
return getFallbackTranslationInstant(langKey, result.substr(2), interpolateParams, Interpolator, sanitizeStrategy);
}
Interpolator.setLocale($uses);
Expand Down
21 changes: 21 additions & 0 deletions test/unit/service/translate.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3015,4 +3015,25 @@ describe('pascalprecht.translate', function () {
expect(failed).toEqual(true);
}));
});

describe('$translate with sce activated', function () {

beforeEach(module('pascalprecht.translate', function ($translateProvider) {
$translateProvider
.translations('en', {
'FOO' : 'foo',
'BAR': 'Bar'
})
.translations('de', {
'FOO' : 'foo'
})
.useSanitizeValueStrategy('sce')
.preferredLanguage('de')
.fallbackLanguage('en');
}));

it('should handle TrustedValueHolderType inner-results', inject(function ($translate) {
expect($translate.instant('BAR').$$unwrapTrustedValue()).toEqual('Bar');
}));
});
});

1 comment on commit 1ede55e

@tommck
Copy link

@tommck tommck commented on 1ede55e Oct 31, 2017

Choose a reason for hiding this comment

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

I agree that "we have to reconsider the result type of this" :)

Please sign in to comment.