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 conteneurs
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
a0d200d2
Non vérifiée
Valider
a0d200d2
rédigé
8 years ago
par
Benjamin Neff
Parcourir les fichiers
Options
Téléchargements
Correctifs
Plain Diff
Update regex for new mention syntax
See #7276
parent
2aa91e0b
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/mentionable.rb
+7
-13
7 ajouts, 13 suppressions
lib/diaspora/mentionable.rb
spec/lib/diaspora/mentionable_spec.rb
+35
-3
35 ajouts, 3 suppressions
spec/lib/diaspora/mentionable_spec.rb
avec
42 ajouts
et
16 suppressions
lib/diaspora/mentionable.rb
+
7
−
13
Voir le fichier @
a0d200d2
module
Diaspora::Mentionable
module
Diaspora::Mentionable
# regex for finding mention markup in plain text
# regex for finding mention markup in plain text:
# ex.
# "message @{user@pod.net} text"
# it can also contain a name, which gets used as the link text:
# "message @{User Name; user@pod.net} text"
# "message @{User Name; user@pod.net} text"
# will yield "User Name" and "user@pod.net"
# will yield "User Name" and "user@pod.net"
REGEX
=
/
(
@\{(
.
+?; [^\}]+)\}
)
/
REGEX
=
/@\{(
?:([^\}]
+?
)
;
)?(
[^\}
]+)\}/
# class attribute that will be added to all mention html links
# class attribute that will be added to all mention html links
PERSON_HREF_CLASS
=
"mention hovercardable"
PERSON_HREF_CLASS
=
"mention hovercardable"
def
self
.
mention_attrs
(
mention_str
)
def
self
.
mention_attrs
(
mention_str
)
mention
=
mention_str
.
match
(
REGEX
)[
2
]
name
,
diaspora_id
=
mention_str
.
match
(
REGEX
).
captures
del_pos
=
mention
.
rindex
(
/;/
)
name
=
mention
[
0
..
(
del_pos
-
1
)].
strip
[
name
.
try
(
:strip
),
diaspora_id
.
strip
]
handle
=
mention
[(
del_pos
+
1
)
..-
1
].
strip
[
name
,
handle
]
end
end
# takes a message text and returns the text with mentions in (html escaped)
# takes a message text and returns the text with mentions in (html escaped)
...
@@ -46,7 +43,7 @@ module Diaspora::Mentionable
...
@@ -46,7 +43,7 @@ module Diaspora::Mentionable
# @return [Array<Person>] array of people
# @return [Array<Person>] array of people
def
self
.
people_from_string
(
msg_text
)
def
self
.
people_from_string
(
msg_text
)
identifiers
=
msg_text
.
to_s
.
scan
(
REGEX
).
map
do
|
match_str
|
identifiers
=
msg_text
.
to_s
.
scan
(
REGEX
).
map
do
|
match_str
|
_
,
identifier
=
m
ention_attrs
(
match_str
.
first
)
identifier
=
m
atch_str
.
second
.
strip
identifier
if
Validation
::
Rule
::
DiasporaId
.
new
.
valid_value?
(
identifier
)
identifier
if
Validation
::
Rule
::
DiasporaId
.
new
.
valid_value?
(
identifier
)
end
end
...
@@ -72,8 +69,6 @@ module Diaspora::Mentionable
...
@@ -72,8 +69,6 @@ module Diaspora::Mentionable
}
}
end
end
private
private_class_method
def
self
.
find_or_fetch_person_by_identifier
(
identifier
)
private_class_method
def
self
.
find_or_fetch_person_by_identifier
(
identifier
)
Person
.
find_or_fetch_by_identifier
(
identifier
)
Person
.
find_or_fetch_by_identifier
(
identifier
)
rescue
DiasporaFederation
::
Discovery
::
DiscoveryError
rescue
DiasporaFederation
::
Discovery
::
DiscoveryError
...
@@ -113,5 +108,4 @@ module Diaspora::Mentionable
...
@@ -113,5 +108,4 @@ module Diaspora::Mentionable
"[
#{
display_name
.
presence
||
person
.
name
}
](
#{
local_or_remote_person_path
(
person
)
}
)"
"[
#{
display_name
.
presence
||
person
.
name
}
](
#{
local_or_remote_person_path
(
person
)
}
)"
end
end
end
end
end
end
Ce diff est replié.
Cliquez pour l'agrandir.
spec/lib/diaspora/mentionable_spec.rb
+
35
−
3
Voir le fichier @
a0d200d2
...
@@ -18,7 +18,27 @@ three "Eve> E.
...
@@ -18,7 +18,27 @@ three "Eve> E.
STR
STR
end
end
describe
"#format"
do
describe
".mention_attrs"
do
it
"returns name and diaspora ID"
do
name
,
diaspora_id
=
Diaspora
::
Mentionable
.
mention_attrs
(
"@{
#{
@names
[
0
]
}
;
#{
@people
[
0
].
diaspora_handle
}
}"
)
expect
(
name
).
to
eq
(
@names
[
0
])
expect
(
diaspora_id
).
to
eq
(
@people
[
0
].
diaspora_handle
)
end
it
"returns only diaspora-ID when no name is included"
do
name
,
diaspora_id
=
Diaspora
::
Mentionable
.
mention_attrs
(
"@{
#{
@people
[
0
].
diaspora_handle
}
}"
)
expect
(
diaspora_id
).
to
eq
(
@people
[
0
].
diaspora_handle
)
expect
(
name
).
to
be_nil
end
it
"trims the name if available"
do
name
,
diaspora_id
=
Diaspora
::
Mentionable
.
mention_attrs
(
"@{
#{
@names
[
0
]
}
;
#{
@people
[
0
].
diaspora_handle
}
}"
)
expect
(
name
).
to
eq
(
@names
[
0
])
expect
(
diaspora_id
).
to
eq
(
@people
[
0
].
diaspora_handle
)
end
end
describe
".format"
do
context
"html output"
do
context
"html output"
do
it
"adds the links to the formatted message"
do
it
"adds the links to the formatted message"
do
fmt_msg
=
Diaspora
::
Mentionable
.
format
(
@test_txt
,
@people
)
fmt_msg
=
Diaspora
::
Mentionable
.
format
(
@test_txt
,
@people
)
...
@@ -64,12 +84,24 @@ STR
...
@@ -64,12 +84,24 @@ STR
end
end
end
end
describe
"
#
people_from_string"
do
describe
"
.
people_from_string"
do
it
"extracts the mentioned people from the text"
do
it
"extracts the mentioned people from the text"
do
ppl
=
Diaspora
::
Mentionable
.
people_from_string
(
@test_txt
)
ppl
=
Diaspora
::
Mentionable
.
people_from_string
(
@test_txt
)
expect
(
ppl
).
to
match_array
(
@people
)
expect
(
ppl
).
to
match_array
(
@people
)
end
end
it
"extracts the mentioned people from the text without name"
do
text
=
"test @{
#{
@people
[
0
].
diaspora_handle
}
} test"
ppl
=
Diaspora
::
Mentionable
.
people_from_string
(
text
)
expect
(
ppl
).
to
match_array
([
@people
[
0
]])
end
it
"extracts the mentioned people from the text mixed mentions (with and without name)"
do
text
=
"@{
#{
@people
[
0
].
diaspora_handle
}
} and @{
#{
@names
[
1
]
}
;
#{
@people
[
1
].
diaspora_handle
}
}"
ppl
=
Diaspora
::
Mentionable
.
people_from_string
(
text
)
expect
(
ppl
).
to
match_array
([
@people
[
0
],
@people
[
1
]])
end
describe
"returns an empty array if nobody was found"
do
describe
"returns an empty array if nobody was found"
do
it
"gets a post without mentions"
do
it
"gets a post without mentions"
do
ppl
=
Diaspora
::
Mentionable
.
people_from_string
(
"post w/o mentions"
)
ppl
=
Diaspora
::
Mentionable
.
people_from_string
(
"post w/o mentions"
)
...
@@ -102,7 +134,7 @@ STR
...
@@ -102,7 +134,7 @@ STR
end
end
end
end
describe
"
#
filter_people"
do
describe
"
.
filter_people"
do
before
do
before
do
@user_a
=
FactoryGirl
.
create
(
:user_with_aspect
,
username:
"user_a"
)
@user_a
=
FactoryGirl
.
create
(
:user_with_aspect
,
username:
"user_a"
)
@user_b
=
FactoryGirl
.
create
(
:user
,
username:
"user_b"
)
@user_b
=
FactoryGirl
.
create
(
:user
,
username:
"user_b"
)
...
...
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