Skip to content

Commit

Permalink
fix(ui5-avatar): image URL may now contain special characters (#1828)
Browse files Browse the repository at this point in the history
  • Loading branch information
vladitasev committed Jun 18, 2020
1 parent fcb2e9e commit 3acab5a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/main/src/Avatar.hbs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<div class="ui5-avatar-root">
{{#if image}}
<span class="ui5-avatar-img" style="background-image: url({{image}})" role="img" aria-label="{{accessibleNameText}}"></span>
<span class="ui5-avatar-img" style="{{styles.img}}" role="img" aria-label="{{accessibleNameText}}"></span>
{{else if icon}}
<ui5-icon class="ui5-avatar-icon" name="{{icon}}" accessible-name="{{accessibleNameText}}"></ui5-icon>
{{else if initials}}
<span class="ui5-avatar-initials">{{validInitials}}</span>
{{/if}}
</div>
</div>
8 changes: 8 additions & 0 deletions packages/main/src/Avatar.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,14 @@ class Avatar extends UI5Element {

return this.i18nBundle.getText(AVATAR_TOOLTIP) || undefined;
}

get styles() {
return {
img: {
"background-image": `url("${encodeURIComponent(this.image)}")`,
},
};
}
}

Avatar.define();
Expand Down
5 changes: 5 additions & 0 deletions packages/main/test/pages/Avatar.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ <h3>Avatar - Basic sample</h3>
<ui5-avatar image="./img/John_Miller.png"></ui5-avatar>
</section>

<section>
<h3>Avatar - special characters in image path</h3>
<ui5-avatar image="./img/John$$$ ' (_)Miller#1.png"></ui5-avatar>
</section>

<section>
<h3>Avatar - Square [ XS, S, M, L, XL ]</h3>
<ui5-avatar image="./img/woman_avatar_5.png" shape="Square" size="XS"></ui5-avatar>
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 3acab5a

Please sign in to comment.