I noticed that Turkish characters get saved differently, based on the specific HTML element control being used (correctly for textarea
, incorrectly for input
).
I am using the following characters for my test: ÖŞĞÜİÇ öşğüıç
Below is my HTML for the input
and textarea
controls (nothing fancy):
<div class="col-md-12">
<div class="row defMarginBottom">
<div class="col-md-6">
<label>Mesaj Konusu</label>
<input type="text" class="form-control" placeholder="Konu"
ng-model="titleText" />
</div>
</div>
<div class="row defMarginBottom">
<div class="col-md-3">
<label>İnternet Adresi Konusu</label>
<input type="text" class="form-control"
placeholder="İnternet Adresi Konusu"
ng-model="additionalDataSubject" />
</div>
<div class="col-md-3 defMarginLeft1_3">
<label>İnternet Adresi Linki</label>
<input type="text" class="form-control"
placeholder="İnternet Adresi Linki"
ng-model="additionalDataLink" />
</div>
</div>
<div class="row defMarginBottom">
<div class="col-md-6">
<label>Mesaj</label>
<textarea class="form-control defHeight"
placeholder="Mesaj" ng-model="message">
</textarea>
</div>
</div>
<div class="row">
<input style="margin-left:1.5%;" type="button"
class="btn btn-success" value="Kaydet ve Gönder"
ng-click="saveAndSend()" />
</div>
</div>
Following is the Angular Controller code where the ng-models are defined:
var jsonObj = {
"Subject": $scope.additionalDataSubject,
"Link": $scope.additionalDataLink
};
var obj = {
"ActivityTypeIds": activityTypeIdList,
"SalesPersonID": $scope.salesPersonId,
"SalesPersons": $scope.spIdList,
"CustomerCategories": categoryIdList,
"customerName": $scope.customerName,
"StartDate": $scope.startDate,
"EndDate": $scope.endDate,
"TitleText": $scope.titleText,
"Message": $scope.message,
"AdditionalData": JSON.stringify(jsonObj)
};
When I enter the test strings, only those for the textarea
controls get saved properly to the database.
Those for input
controls are saved incorrectly as: ÖŞĞÜİÇ öşğüıç
Note: I recently added the following new directive to my Angular app as a protection agaist XSS attacks, and was suspicious of it as causing the problem, but since the entries for textarea
are saved correctly, I'm not sure if it is related.
.directive('input',['$sanitize', function ($sanitize) {
return {
restrict: 'E',
require: '?ngModel',
link: function (scope, element, attrs, ngModel) {
if (ngModel !== undefined && ngModel != null) {
ngModel.$parsers.push(function (value) {
return $sanitize(value);
});
}
}
};
}]);
How can I overcome this problem? Most of the questions here on SO are about rendering of Turkish characters, not about saving them.