Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 6e29c1e

Browse files
committedAug 17, 2012
Bugnote '~' processing may produce error if bug does not exist
This error case is a bit far-fetched, and should normally not occur unless there is some data corruption. If referencing an existing bugnote whose parent bug is not in the database, the callback function cannot retrieve the project_id, so error 403 is triggered. The callback functions have also been reformatted for better readability Fixes #12580
1 parent 83fb71b commit 6e29c1e

File tree

1 file changed

+47
-28
lines changed

1 file changed

+47
-28
lines changed
 

‎core/string_api.php

+47-28
Original file line numberDiff line numberDiff line change
@@ -404,35 +404,54 @@ function string_process_bugnote_link( $p_string, $p_include_anchor = true, $p_de
404404

405405
if( !isset( $string_process_bugnote_link_callback[$p_include_anchor][$p_detail_info][$p_fqdn] ) ) {
406406
if( $p_include_anchor ) {
407-
$string_process_bugnote_link_callback[$p_include_anchor][$p_detail_info][$p_fqdn] = create_function( '$p_array', '
408-
if ( bugnote_exists( (int)$p_array[2] ) ) {
409-
$t_bug_id = bugnote_get_field( (int)$p_array[2], \'bug_id\' );
410-
$g_project_override = bug_get_field( $t_bug_id, \'project_id\' );
411-
if ( bug_exists( $t_bug_id ) && ( access_compare_level( user_get_access_level( auth_get_current_user_id(), bug_get_field( $t_bug_id, \'project_id\' ) ), config_get( \'private_bugnote_threshold\' ) ) || ( bugnote_get_field( (int)$p_array[2], \'reporter_id\' ) == auth_get_current_user_id() ) || bugnote_get_field( (int)$p_array[2], \'view_state\' ) == VS_PUBLIC ) ) {
412-
$g_project_override = null;
413-
return $p_array[1] . string_get_bugnote_view_link( $t_bug_id, (int)$p_array[2], null, ' . ( $p_detail_info ? 'true' : 'false' ) . ', ' . ( $p_fqdn ? 'true' : 'false' ) . ' );
414-
} else {
415-
$g_project_override = null;
416-
return $p_array[0];
417-
}
418-
} else {
419-
return $p_array[0];
420-
}
421-
' );
407+
$string_process_bugnote_link_callback[$p_include_anchor][$p_detail_info][$p_fqdn] =
408+
create_function( '$p_array',
409+
'
410+
if ( bugnote_exists( (int)$p_array[2] ) ) {
411+
$t_bug_id = bugnote_get_field( (int)$p_array[2], \'bug_id\' );
412+
if ( bug_exists( $t_bug_id ) ) {
413+
$g_project_override = bug_get_field( $t_bug_id, \'project_id\' );
414+
if ( access_compare_level(
415+
user_get_access_level( auth_get_current_user_id(),
416+
bug_get_field( $t_bug_id, \'project_id\' ) ),
417+
config_get( \'private_bugnote_threshold\' )
418+
)
419+
|| bugnote_get_field( (int)$p_array[2], \'reporter_id\' ) == auth_get_current_user_id()
420+
|| bugnote_get_field( (int)$p_array[2], \'view_state\' ) == VS_PUBLIC
421+
) {
422+
$g_project_override = null;
423+
return $p_array[1] .
424+
string_get_bugnote_view_link(
425+
$t_bug_id,
426+
(int)$p_array[2],
427+
null,
428+
' . ( $p_detail_info ? 'true' : 'false' ) . ', ' . ( $p_fqdn ? 'true' : 'false' ) . '
429+
);
430+
}
431+
$g_project_override = null;
432+
}
433+
}
434+
return $p_array[0];
435+
'
436+
);
422437
} else {
423-
$string_process_bugnote_link_callback[$p_include_anchor][$p_detail_info][$p_fqdn] = create_function( '$p_array', '
424-
# We might as well create the link here even if the bug
425-
# doesnt exist. In the case above we dont want to do
426-
# the summary lookup on a non-existant bug. But here, we
427-
# can create the link and by the time it is clicked on, the
428-
# bug may exist.
429-
$t_bug_id = bugnote_get_field( (int)$p_array[2], \'bug_id\' );
430-
if ( bug_exists( $t_bug_id ) ) {
431-
return $p_array[1] . string_get_bugnote_view_url_with_fqdn( $t_bug_id, (int)$p_array[2], null );
432-
} else {
433-
return $p_array[0];
434-
}
435-
' );
438+
$string_process_bugnote_link_callback[$p_include_anchor][$p_detail_info][$p_fqdn] =
439+
create_function(
440+
'$p_array',
441+
'
442+
# We might as well create the link here even if the bug
443+
# doesnt exist. In the case above we dont want to do
444+
# the summary lookup on a non-existant bug. But here, we
445+
# can create the link and by the time it is clicked on, the
446+
# bug may exist.
447+
$t_bug_id = bugnote_get_field( (int)$p_array[2], \'bug_id\' );
448+
if ( bug_exists( $t_bug_id ) ) {
449+
return $p_array[1] . string_get_bugnote_view_url_with_fqdn( $t_bug_id, (int)$p_array[2], null );
450+
} else {
451+
return $p_array[0];
452+
}
453+
'
454+
);
436455
}
437456
}
438457
$p_string = preg_replace_callback( '/(^|[^\w])' . preg_quote( $t_tag, '/' ) . '(\d+)\b/', $string_process_bugnote_link_callback[$p_include_anchor][$p_detail_info][$p_fqdn], $p_string );

0 commit comments

Comments
 (0)
Please sign in to comment.