Skip to content
GitLab
Explorer
Connexion
S'inscrire
Navigation principale
Rechercher ou aller à…
Projet
P
parlote-facil
Gestion
Activité
Membres
Labels
Programmation
Tickets
Tableaux des tickets
Jalons
Wiki
Code
Requêtes de fusion
Dépôt
Branches
Validations
Étiquettes
Graphe du dépôt
Comparer les révisions
Extraits de code
Compilation
Pipelines
Jobs
Planifications de pipeline
Artéfacts
Déploiement
Releases
Registre de paquets
Registre de conteneur
Registre de modèles
Opération
Environnements
Modules Terraform
Surveillance
Incidents
Analyse
Données d'analyse des chaînes de valeur
Analyse des contributeurs
Données d'analyse CI/CD
Données d'analyse du dépôt
Expériences du modèle
Aide
Aide
Support
Documentation de GitLab
Comparer les forfaits GitLab
Forum de la communauté
Contribuer à GitLab
Donner votre avis
Raccourcis clavier
?
Extraits de code
Groupes
Projets
Afficher davantage de fils d'Ariane
facil
parlote-facil
Validations
5f5d8c5e
Non vérifiée
Valider
5f5d8c5e
rédigé
7 years ago
par
Benjamin Neff
Parcourir les fichiers
Options
Téléchargements
Correctifs
Plain Diff
Replace diaspora:// links in the text
parent
4a994b0a
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Modifications
2
Masquer les modifications d'espaces
En ligne
Côte à côte
Affichage de
2 fichiers modifiés
lib/diaspora/message_renderer.rb
+11
-0
11 ajouts, 0 suppression
lib/diaspora/message_renderer.rb
spec/lib/diaspora/message_renderer_spec.rb
+80
-8
80 ajouts, 8 suppressions
spec/lib/diaspora/message_renderer_spec.rb
avec
91 ajouts
et
8 suppressions
lib/diaspora/message_renderer.rb
+
11
−
0
Voir le fichier @
5f5d8c5e
...
...
@@ -95,6 +95,12 @@ module Diaspora
def
normalize
@message
=
self
.
class
.
normalize
(
@message
)
end
def
diaspora_links
@message
=
@message
.
gsub
(
DiasporaFederation
::
Federation
::
DiasporaUrlParser
::
DIASPORA_URL_REGEX
)
{
|
match_str
|
Regexp
.
last_match
(
2
)
==
"post"
?
AppConfig
.
url_to
(
"/posts/
#{
Regexp
.
last_match
(
3
)
}
"
)
:
match_str
}
end
end
DEFAULTS
=
{
mentioned_people:
[],
...
...
@@ -158,6 +164,7 @@ module Diaspora
def
plain_text
opts
=
{}
process
(
opts
)
{
make_mentions_plain_text
diaspora_links
squish
append_and_truncate
}
...
...
@@ -167,6 +174,7 @@ module Diaspora
def
plain_text_without_markdown
opts
=
{}
process
(
opts
)
{
make_mentions_plain_text
diaspora_links
strip_markdown
squish
append_and_truncate
...
...
@@ -177,6 +185,7 @@ module Diaspora
def
plain_text_for_json
opts
=
{}
process
(
opts
)
{
normalize
diaspora_links
camo_urls
if
AppConfig
.
privacy
.
camo
.
proxy_markdown_images?
}
end
...
...
@@ -186,6 +195,7 @@ module Diaspora
process
(
opts
)
{
escape
normalize
diaspora_links
render_mentions
render_tags
squish
...
...
@@ -198,6 +208,7 @@ module Diaspora
process
(
opts
)
{
process_newlines
normalize
diaspora_links
camo_urls
if
AppConfig
.
privacy
.
camo
.
proxy_markdown_images?
markdownify
render_mentions
...
...
Ce diff est replié.
Cliquez pour l'agrandir.
spec/lib/diaspora/message_renderer_spec.rb
+
80
−
8
Voir le fichier @
5f5d8c5e
# frozen_string_literal: true
describe
Diaspora
::
MessageRenderer
do
MESSAGE_NORMALIZTIONS
=
{
"
\u
202a#
\u
200eUSA
\u
202c"
=>
"#USA"
,
"ള്"
=>
"ള്"
}
def
message
(
text
,
opts
=
{})
Diaspora
::
MessageRenderer
.
new
(
text
,
opts
)
end
...
...
@@ -100,6 +95,20 @@ describe Diaspora::MessageRenderer do
end
end
end
context
"with diaspora:// links"
do
it
"replaces diaspora:// links with pod-local links"
do
target
=
FactoryGirl
.
create
(
:status_message
)
expect
(
message
(
"Have a look at diaspora://
#{
target
.
diaspora_handle
}
/post/
#{
target
.
guid
}
."
).
html
).
to
match
(
/Have a look at
#{
AppConfig
.
url_to
(
"/posts/
#{
target
.
guid
}
"
)
}
./
)
end
it
"doesn't touch invalid diaspora:// links"
do
text
=
"You can create diaspora://author/type/guid links!"
expect
(
message
(
text
).
html
).
to
match
(
/
#{
text
}
/
)
end
end
end
describe
"#markdownified"
do
...
...
@@ -128,8 +137,11 @@ describe Diaspora::MessageRenderer do
end
it
"normalizes"
do
MESSAGE_NORMALIZTIONS
.
each
do
|
input
,
output
|
expect
(
message
(
input
).
plain_text_for_json
).
to
eq
output
{
"
\u
202a#
\u
200eUSA
\u
202c"
=>
"<p><a class=
\"
tag
\"
href=
\"
/tags/USA
\"
>#USA</a></p>
\n
"
,
"ള്"
=>
"<p>ള്</p>
\n
"
}.
each
do
|
input
,
output
|
expect
(
message
(
input
).
markdownified
).
to
eq
output
end
end
...
...
@@ -180,6 +192,25 @@ describe Diaspora::MessageRenderer do
entities
=
'& ß ' ' "'
expect
(
message
(
entities
).
markdownified
).
to
eq
"<p>
#{
entities
}
</p>
\n
"
end
context
"with diaspora:// links"
do
it
"replaces diaspora:// links with pod-local links"
do
target1
=
FactoryGirl
.
create
(
:status_message
)
target2
=
FactoryGirl
.
create
(
:status_message
)
text
=
"Have a look at [this post](diaspora://
#{
target1
.
diaspora_handle
}
/post/
#{
target1
.
guid
}
) and "
\
"this one too diaspora://
#{
target2
.
diaspora_handle
}
/post/
#{
target2
.
guid
}
."
rendered
=
message
(
text
).
markdownified
expect
(
rendered
).
to
match
(
%r{at <a href="
#{
AppConfig
.
url_to
(
"/posts/
#{
target1
.
guid
}
"
)
}
">this post</a> and}
)
expect
(
rendered
).
to
match
(
/this one too
#{
AppConfig
.
url_to
(
"/posts/
#{
target2
.
guid
}
"
)
}
./
)
end
it
"doesn't touch invalid diaspora:// links"
do
text
=
"You can create diaspora://author/type/guid links!"
expect
(
message
(
text
).
markdownified
).
to
match
(
/
#{
text
}
/
)
end
end
end
end
...
...
@@ -210,6 +241,25 @@ describe Diaspora::MessageRenderer do
expect
(
msg
.
plain_text_without_markdown
).
to
eq
"@
#{
alice
.
diaspora_handle
}
is cool"
end
end
context
"with diaspora:// links"
do
it
"replaces diaspora:// links with pod-local links"
do
target1
=
FactoryGirl
.
create
(
:status_message
)
target2
=
FactoryGirl
.
create
(
:status_message
)
text
=
"Have a look at [this post](diaspora://
#{
target1
.
diaspora_handle
}
/post/
#{
target1
.
guid
}
) and "
\
"this one too diaspora://
#{
target2
.
diaspora_handle
}
/post/
#{
target2
.
guid
}
."
rendered
=
message
(
text
).
plain_text_without_markdown
expect
(
rendered
).
to
match
(
/look at this post \(
#{
AppConfig
.
url_to
(
"/posts/
#{
target1
.
guid
}
"
)
}
\) and/
)
expect
(
rendered
).
to
match
(
/this one too
#{
AppConfig
.
url_to
(
"/posts/
#{
target2
.
guid
}
"
)
}
./
)
end
it
"doesn't touch invalid diaspora:// links"
do
text
=
"You can create diaspora://author/type/guid links!"
expect
(
message
(
text
).
plain_text_without_markdown
).
to
match
(
/
#{
text
}
/
)
end
end
end
describe
"#urls"
do
...
...
@@ -241,9 +291,31 @@ describe Diaspora::MessageRenderer do
describe
"#plain_text_for_json"
do
it
"normalizes"
do
MESSAGE_NORMALIZTIONS
.
each
do
|
input
,
output
|
{
"
\u
202a#
\u
200eUSA
\u
202c"
=>
"#USA"
,
"ള്"
=>
"ള്"
}.
each
do
|
input
,
output
|
expect
(
message
(
input
).
plain_text_for_json
).
to
eq
output
end
end
context
"with diaspora:// links"
do
it
"replaces diaspora:// links with pod-local links"
do
target1
=
FactoryGirl
.
create
(
:status_message
)
target2
=
FactoryGirl
.
create
(
:status_message
)
text
=
"Have a look at [this post](diaspora://
#{
target1
.
diaspora_handle
}
/post/
#{
target1
.
guid
}
) and "
\
"this one too diaspora://
#{
target2
.
diaspora_handle
}
/post/
#{
target2
.
guid
}
."
rendered
=
message
(
text
).
plain_text_for_json
expect
(
rendered
).
to
match
(
/look at \[this post\]\(
#{
AppConfig
.
url_to
(
"/posts/
#{
target1
.
guid
}
"
)
}
\) and/
)
expect
(
rendered
).
to
match
(
/this one too
#{
AppConfig
.
url_to
(
"/posts/
#{
target2
.
guid
}
"
)
}
./
)
end
it
"doesn't touch invalid diaspora:// links"
do
text
=
"You can create diaspora://author/type/guid links!"
expect
(
message
(
text
).
plain_text_for_json
).
to
match
(
/
#{
text
}
/
)
end
end
end
end
Ce diff est replié.
Cliquez pour l'agrandir.
Aperçu
0%
Chargement en cours
Veuillez réessayer
ou
joindre un nouveau fichier
.
Annuler
You are about to add
0
people
to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Enregistrer le commentaire
Annuler
Veuillez vous
inscrire
ou vous
se connecter
pour commenter